1

Ich habe ein lineares Layout innerhalb eines relativen Layouts und ich versuche, das übergeordnete Layout relativ zum unteren Rand des Bildschirms auszurichten.Andorid: Wie ordne ich alle Elemente im relativen Layout am unteren Rand des Bildschirms

<RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom"> 
     <TextView 
      android:id="@+id/fruits" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Fruits" 
      android:layout_centerHorizontal="true" 
      /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="16sp" 
      android:layout_alignParentBottom="true" 
      android:gravity="bottom"> 
      <TextView 
       android:id="@+id/message" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:text="Message: " /> 
      <EditText 
       android:id="@+id/message_text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

     </LinearLayout> 
    </RelativeLayout> 

Im Grunde ein Text zum Zentrum versucht, und es gibt einen Text und Text bearbeiten unter ihm und richten sie alle an den unteren Rand des Bildschirms Diese

  Fruits 
Message: ___________________________ 
+0

würden Sie ein Bild zeichnen, um deutlich zu machen, wo man Dinge sein wollen!? – MohammedAlSafwan

+0

Ich möchte diese ganze Sache am unteren Rand des Bildschirms sein –

Antwort

0

Wechsel:

<RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom"> 

zu diesem:

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="bottom"> 
0

Verwenden Sie android:layout_alignParentBottom="true" Überprüfen Sie, ob die folgende Lösung in Ihrem Projekt ausgeführt wird.

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" > 
    <TextView 
     android:id="@+id/fruits" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Fruits" 
     android:layout_alignTop="@+id/linearLayout2" 
     android:layout_centerHorizontal="true" /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="16sp" 
     android:layout_alignParentBottom="true" 
     android:gravity="bottom" 
     android:id="@+id/linearLayout2"> 
     <TextView 
      android:id="@+id/message" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="Message: " /> 
     <EditText 
      android:id="@+id/message_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 
</RelativeLayout> 
+0

Ich denke, dass dieses Attribut für Kinder von RelativeLayout ist, nicht das Layout selbst –

+0

für dieses Attribut zu arbeiten sollte es relatives Layout als Elternteil zu haben. –

0

Sie benötigen Android verwenden: layout_alignParentBottom = "true"

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical">  
</LinearLayout> 


<android.support.v7.widget.AppCompatButton 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" // add this to you layout 
    android:layout_margin="@dimen/margin_10" 
    android:background="@drawable/button_selector"/> 

    </RelativeLayout> 
0

einfach! Sie müssen die Höhe des Parent RelativeLayout von von wrap_content zu match_parent ändern. Damit wird die gesamte Höhe des Layouts erreicht und es wird an den unteren Bildschirmrand angehängt.

0

gesetzt layout_above Eigenschaft Früchte Textview nach unten Linearlayout Versuchen Sie, diese

<RelativeLayout android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="bottom" 
xmlns:android="http://schemas.android.com/apk/res/android"> 
<TextView 
    android:id="@+id/fruits" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Fruits" 
    android:layout_above="@+id/bottomLayout" 
    android:layout_centerHorizontal="true" 
    /> 
<LinearLayout 
    android:id="@+id/bottomLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="16sp" 
    android:layout_alignParentBottom="true" 
    android:gravity="bottom"> 
    <TextView 
     android:id="@+id/message" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:text="Message: " /> 
    <EditText 
     android:id="@+id/message_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 
</RelativeLayout> 
Verwandte Themen