2013-04-17 10 views
5

Ich stehe mit Problem Taste zeigt außerhalb des Bildschirms in RelativeLayout. ImageView skaliert das Bild nicht, um einem Button sichtbaren Platz zu geben.Wie kann ich RelativeLayout zum Bildschirm passen?

Was ich habe:

enter image description here

Was ich will:

enter image description here

Code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center_vertical" > 

<TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:textAppearance="@android:style/TextAppearance.Small" 
     android:textColor="?android:attr/textColorTertiary" 
     android:layout_centerHorizontal="true" 
     /> 

<ru.mw.widget.DrawableImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView" 
     android:adjustViewBounds="true" 
     android:layout_centerHorizontal="true" 
     android:scaleType="centerCrop" 
     /> 

<Button 
     android:id="@+id/processButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:layout_below="@+id/imageView" 
     android:layout_centerHorizontal="true" 
     /> 

Problem, wenn ich die Bildschirmausrichtung zu ändern: Wenn ich Arun C Thomas's method im Landscape-Modus alles verwenden ist ok, aber im Portrait-Modus Ich habe dieses (Bild von links/rechts Kanten abgeschnitten):

enter image description here Was erwartet:

enter image description here

+0

hinzufügen android: alignParentBottom auf Ihre Taste und Android: alignParentTop (beide = true), um Ihre Textview. Sie setzen im Moment keine Grenzen für Ihr ImageView. –

Antwort

2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center_vertical" > 

<TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:textColor="?android:attr/textColorTertiary" 
     android:textAppearance="@android:style/TextAppearance.Small" 

     android:layout_centerHorizontal="true" 
     /> 

<ru.mw.widget.DrawableImageView 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_below="@+id/textView" 
    android:layout_centerHorizontal="true" 
    android:adjustViewBounds="true" 
    android:scaleType="centerCrop" 
    android:layout_above="@+id/processButton" 
    /> 

<Button 
     android:id="@+id/processButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     /> 
</RelativeLayout> 
Diese

ist die Lösung

Nun ist die Aktualisiert Anforderung fügen Sie den oben Layout layout-land Ordner in res zu erreichen jetzt in Standard layout Ordner hinzufügen (wenn Sie nicht über einen Ordner mit dem Namen layout-land in res haben erstellen) dieses xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" > 
<ru.mw.widget.DrawableImageView 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:adjustViewBounds="true" 
    /> 

<Button 
    android:id="@+id/processButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageView" 
    android:layout_centerHorizontal="true" 
    android:text="@string/str" /> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/imageView" 
    android:layout_centerHorizontal="true" 
    android:text="@string/str" 
    android:textColor="?android:attr/textColorTertiary" /> 

</RelativeLayout> 

Das ist es.

+0

Schönes Beispiel, +1, aber ich bearbeite meine Frage für ein wenig ... – ADK

+0

bearbeitet die Antwort finden Sie unter –

+0

Ich hoffte, dass dies mit einem Layout erreicht werden konnte, aber Sie sind richtig, danke! – ADK

1

Try android:layout_alignParentBottom="true" auf die Schaltfläche hinzufügen:

<Button 
    android:id="@+id/processButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/str" 
    android:layout_below="@+id/imageView" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentBottom="true" 
    /> 
1
  1. den Knopf an Mutterboden ausrichten layout_alignParentBottom="true" verwenden.
  2. Wickeln Sie die ImageView zwischen dem TextView und Button

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center_vertical" > 

<TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:textAppearance="@android:style/TextAppearance.Small" 
     android:textColor="?android:attr/textColorTertiary" 
     android:layout_centerHorizontal="true" 
     /> 

<Button 
     android:id="@+id/processButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     /> 

<ru.mw.widget.DrawableImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView" 
     android:layout_above="@+id/processButton" 
     android:adjustViewBounds="true" 
     android:layout_centerHorizontal="true" 
     android:scaleType="centerCrop" 
     /> 

</RelativeLayout> 
Verwandte Themen