2016-04-02 4 views
1

Ich füge das folgende Layout ein.Relatives Layout für den Wrap-Inhalt wird wegen Kreisabhängigkeit in den Vollbildmodus versetzt

Sie haben ein äußeres Relatives Layout, und darin befinden sich zwei Layouts, deren IDs l_first (lineares Layout) und Slider (relatives Layout) lauten. Das Slider-Layout ist ein Layout, das ich am unteren Rand des Gerätebildschirms ausrichten möchte. Es sollte die Höhe des Inhalts (mehrere Layouts und Ansichten) in ihm haben. Die Unterseite von l_first sollte zwischen dem oberen Bildschirmrand und dem oberen Rand des Sliders liegen.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent"  
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="com.example.raw.myapp.NewActivity" 
android:background="#f2f2f2"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:id="@+id/l_first"> 

    <Button 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Button" 
     android:id="@+id/button" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" /> 
</RelativeLayout> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:weightSum="1" 
    android:id="@+id/slider" 
    android:background="#e6e6e6"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="Rental" 
     android:layout_above="@+id/l_ten_ow" 
     android:id="@+id/t_rental" 
     android:layout_centerHorizontal="true" 
     android:textSize="15dp" 
     android:textColor="#000000" 
     android:textIsSelectable="true" /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/l_ptype" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/l_ten_ow"> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="I am a tenant" 
      android:id="@+id/btn1" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="0.5" 
      android:textColor="#008000" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="I am a owner" 
      android:id="@+id/btn2" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="0.5" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/l_ptype_label" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/l_ptype" 
     android:paddingBottom="10dp" 
     android:visibility="visible"> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:layout_weight="0.25" 
      android:id="@+id/ib_home" 
      android:src="@drawable/home1" 
      android:background="#00000000" 
      android:nestedScrollingEnabled="false" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:layout_weight="0.25" 
      android:id="@+id/ib_shop" 
      android:src="@drawable/shop" 
      android:background="#00000000" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:id="@+id/ib_industry" 
      android:src="@drawable/industrial" 
      android:background="#00000000" 
      android:layout_weight="0.25" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:id="@+id/ib_office" 
      android:src="@drawable/office" 
      android:background="#00000000" 
      android:layout_weight="0.25" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/r_p_subtype" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/l_ptype_label" 
     android:visibility="visible"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="home" 
      android:id="@+id/textView3" 
      android:layout_weight="0.25" 
      android:textAlignment="center" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="shop" 
      android:id="@+id/sho" 
      android:layout_weight="0.25" 
      android:textAlignment="center" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="industrial" 
      android:id="@+id/ind" 
      android:layout_weight="0.25" 
      android:textAlignment="center" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="office" 
      android:id="@+id/textView6" 
      android:layout_weight="0.25" 
      android:textAlignment="center" /> 
    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/l_budget" 
     android:id="@+id/r_p_subtype"> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_above="@+id/btn_oye" 
     android:id="@+id/l_budget"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Budget" 
      android:id="@+id/budget" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="10k" 
      android:id="@+id/textView4" 
      android:layout_below="@+id/budget" 
      android:layout_centerVertical="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <SeekBar 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/seekBar" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:layout_toEndOf="@+id/budget" 
      android:layout_toRightOf="@+id/budget" 
      android:indeterminate="false" 
      android:progressTint="#39ac73" 
      android:thumb="@drawable/home" /> 

    </RelativeLayout> 


    <Button 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:layout_alignParentBottom="true" 
     android:text="Oye" 
     android:id="@+id/btn_oye" 
     android:background="#39ac73" 
     android:clickable="true" 
     android:contextClickable="true" /> 

</RelativeLayout> 

+0

Kreisabhängigkeit ist aufgrund android: layout_alignParentBottom = "true" in btn_oye gesetzt ist, aber wenn ich es entfernen Layout messed wird – Ritzor

Antwort

0

Ihr Ziel erreichen Sie eine lineare Layout

machen es wie folgt verwenden sollte:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="com.example.raw.myapp.NewActivity" 
android:background="#f2f2f2"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:gravity="bottom"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:id="@+id/l_first" 
     android:layout_weight="1"> 

     <Button 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Button" 
      android:id="@+id/button" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 
    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/slider" 
     android:orientation="vertical" 
     android:gravity="bottom" 
     android:background="#e6e6e6"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="Rental" 
      android:layout_above="@+id/l_ten_ow" 
      android:id="@+id/t_rental" 
      android:layout_centerHorizontal="true" 
      android:textSize="15dp" 
      android:textColor="#000000" 
      android:textIsSelectable="true" /> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/l_ptype" 
      android:layout_centerHorizontal="true" 
      android:id="@+id/l_ten_ow"> 
      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="I am a tenant" 
       android:id="@+id/btn1" 
       android:layout_gravity="center_vertical" 
       android:layout_weight="0.5" 
       android:textColor="#008000" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="I am a owner" 
       android:id="@+id/btn2" 
       android:layout_gravity="center_vertical" 
       android:layout_weight="0.5" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/l_ptype_label" 
      android:layout_centerHorizontal="true" 
      android:id="@+id/l_ptype" 
      android:paddingBottom="10dp" 
      android:visibility="visible"> 

      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="50dp" 
       android:layout_weight="0.25" 
       android:id="@+id/ib_home" 
       android:src="@drawable/home1" 
       android:background="#00000000" 
       android:nestedScrollingEnabled="false" /> 

      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="50dp" 
       android:layout_weight="0.25" 
       android:id="@+id/ib_shop" 
       android:src="@drawable/shop" 
       android:background="#00000000" /> 

      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="50dp" 
       android:id="@+id/ib_industry" 
       android:src="@drawable/industrial" 
       android:background="#00000000" 
       android:layout_weight="0.25" /> 

      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="50dp" 
       android:id="@+id/ib_office" 
       android:src="@drawable/office" 
       android:background="#00000000" 
       android:layout_weight="0.25" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/r_p_subtype" 
      android:layout_centerHorizontal="true" 
      android:id="@+id/l_ptype_label" 
      android:visibility="visible"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:text="home" 
       android:id="@+id/textView3" 
       android:layout_weight="0.25" 
       android:textAlignment="center" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:text="shop" 
       android:id="@+id/sho" 
       android:layout_weight="0.25" 
       android:textAlignment="center" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:text="industrial" 
       android:id="@+id/ind" 
       android:layout_weight="0.25" 
       android:textAlignment="center" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:text="office" 
       android:id="@+id/textView6" 
       android:layout_weight="0.25" 
       android:textAlignment="center" /> 
     </LinearLayout> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/l_budget" 
      android:id="@+id/r_p_subtype"> 

     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_above="@+id/btn_oye" 
      android:id="@+id/l_budget"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Budget" 
       android:id="@+id/budget" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="10k" 
       android:id="@+id/textView4" 
       android:layout_below="@+id/budget" 
       android:layout_centerVertical="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 

      <SeekBar 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/seekBar" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" 
       android:layout_toEndOf="@+id/budget" 
       android:layout_toRightOf="@+id/budget" 
       android:indeterminate="false" 
       android:progressTint="#39ac73" 
       android:thumb="@drawable/home" /> 

     </RelativeLayout> 


     <Button 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="fill_parent" 
      android:layout_height="40dp" 
      android:layout_alignParentBottom="true" 
      android:text="Oye" 
      android:id="@+id/btn_oye" 
      android:background="#39ac73" 
      android:clickable="true" 
      android:contextClickable="true" /> 

    </LinearLayout> 

</LinearLayout> 
</RelativeLayout> 

Es gibt zwei wichtige Hinweise:

  1. Ihr lineares Layout sollte einen Tiefpunkt haben, dh es berechnet die Höhe von unten.
  2. die Ansicht, die Sie den Rest des Raumes bekommen wollen, sollte ein Gewicht von 1 haben !!!
Verwandte Themen