2016-03-08 97 views
0

進出口試圖對準兩個按鈕(「重置」和「應用」)在底部,但它總是將自己屏幕無法將按鈕定位到屏幕底部

`

頂部
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/form_bg"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:id="@+id/strp" 
     android:orientation="horizontal"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <com.widget.AppButton 
       android:id="@+id/country_filter" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/button_config" 
       android:gravity="left" 
       android:padding="10dp" 
       android:text="Country" 
       android:textColor="#000" 
       android:textSize="32sp" 
       android:textStyle="italic" /> 

      <com.widget.AppButton 
       android:id="@+id/domain_filter" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/button_config" 
       android:gravity="left" 
       android:padding="10dip" 
       android:text="Domain" 
       android:textColor="#000" 
       android:textSize="32sp" 
       android:textStyle="italic" /> 

      <com.widget.AppButton 
       android:id="@+id/unit_filter" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:background="@drawable/button_config" 
       android:gravity="left" 
       android:padding="10dp" 
       android:text="Unit" 
       android:textColor="#000" 
       android:textSize="32sp" 
       android:textStyle="italic" /> 


     </LinearLayout> 

     <View 
      android:layout_width="1px" 
      android:layout_height="match_parent" 
      android:background="@drawable/white_divider" /> 

     <View 
      android:layout_width="1px" 
      android:layout_height="match_parent" 
      android:background="@drawable/black_divider" /> 

    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignBottom="@+id/strp" 
     android:layout_alignParentBottom="true"> 

     <com.widget.AppButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Reset" 
      android:textStyle="bold" 
      android:id="@+id/button" 
      style="@style/btn" 
      android:layout_weight="1"/> 

     <com.widget.AppButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Apply" 
      android:textStyle="bold" 
      android:id="@+id/button2" 
      style="@style/btn" 
      android:layout_weight="1"/> 
    </LinearLayout> 


</RelativeLayout>` 

我的課程設置layout_alignParentBottom爲真,但仍問題仍然存在

+1

刪除'android:layout_alignBottom =「@ + id/strp」'並將高度設置爲'wrap_content'。 –

+0

嘗試刪除android:layout_alignBottom =「@ + id/strp」' – Mohit

+0

請使用LinearLayout來代替 –

回答

3

你應該改變你的最後LinearLayout通過

  • 刪除android:layout_alignBottom="@+id/strp"
  • 變化android:layout_height="match_parent"android:layout_height="wrap_content"

因此,代碼應該是

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/form_bg"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:id="@+id/strp" 
     android:orientation="horizontal"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <com.widget.AppButton 
       android:id="@+id/country_filter" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/button_config" 
       android:gravity="left" 
       android:padding="10dp" 
       android:text="Country" 
       android:textColor="#000" 
       android:textSize="32sp" 
       android:textStyle="italic" /> 

      <com.widget.AppButton 
       android:id="@+id/domain_filter" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/button_config" 
       android:gravity="left" 
       android:padding="10dip" 
       android:text="Domain" 
       android:textColor="#000" 
       android:textSize="32sp" 
       android:textStyle="italic" /> 

      <com.widget.AppButton 
       android:id="@+id/unit_filter" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:background="@drawable/button_config" 
       android:gravity="left" 
       android:padding="10dp" 
       android:text="Unit" 
       android:textColor="#000" 
       android:textSize="32sp" 
       android:textStyle="italic" /> 


     </LinearLayout> 

     <View 
      android:layout_width="1px" 
      android:layout_height="match_parent" 
      android:background="@drawable/white_divider" /> 

     <View 
      android:layout_width="1px" 
      android:layout_height="match_parent" 
      android:background="@drawable/black_divider" /> 

    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 

     <com.widget.AppButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Reset" 
      android:textStyle="bold" 
      android:id="@+id/button" 
      style="@style/btn" 
      android:layout_weight="1"/> 

     <com.widget.AppButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Apply" 
      android:textStyle="bold" 
      android:id="@+id/button2" 
      style="@style/btn" 
      android:layout_weight="1"/> 
    </LinearLayout> 


</RelativeLayout> 
1

建議你,改變你的的RelativeLayout到的LinearLayout,因爲你不需要放棄使用額外的屬性和刪除參數無效FR OM是佈局文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/form_bg" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:id="@+id/strp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <com.widget.AppButton 
       android:id="@+id/country_filter" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/button_config" 
       android:gravity="left" 
       android:padding="10dp" 
       android:text="Country" 
       android:textColor="#000" 
       android:textSize="32sp" 
       android:textStyle="italic" /> 

      <com.widget.AppButton 
       android:id="@+id/domain_filter" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/button_config" 
       android:gravity="left" 
       android:padding="10dip" 
       android:text="Domain" 
       android:textColor="#000" 
       android:textSize="32sp" 
       android:textStyle="italic" /> 

      <com.widget.AppButton 
       android:id="@+id/unit_filter" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:background="@drawable/button_config" 
       android:gravity="left" 
       android:padding="10dp" 
       android:text="Unit" 
       android:textColor="#000" 
       android:textSize="32sp" 
       android:textStyle="italic" /> 


     </LinearLayout> 

     <View 
      android:layout_width="1px" 
      android:layout_height="match_parent" 
      android:background="@drawable/white_divider" /> 

     <View 
      android:layout_width="1px" 
      android:layout_height="match_parent" 
      android:background="@drawable/black_divider" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal"> 

     <com.widget.AppButton 
      android:id="@+id/button" 
      style="@style/btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Reset" 
      android:textStyle="bold" /> 

     <com.widget.AppButton 
      android:id="@+id/button2" 
      style="@style/btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Apply" 
      android:textStyle="bold" /> 
    </LinearLayout> 


</LinearLayout> 
+0

你改變了什麼,爲什麼?不要只是轉儲代碼 –

1

android:layout_alignBottom=" "工作得更好時,相對佈局裏面,請嘗試使用一個相對佈局內。也可以在按鈕上使用android:layout_alignBottom=" "而不是在佈局上。

<RelativeLayout // Changed it to RL 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" // Removed AlignBottom 
    android:orientation="horizontal"> 

    <com.widget.AppButton 
     android:id="@+id/button" 
     style="@style/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_alignBottom="true" // this one 
     android:text="Reset" 
     android:textStyle="bold" /> 

    <com.widget.AppButton 
     android:id="@+id/button2" 
     style="@style/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_alignBottom="true" // This one 
     android:text="Apply" 
     android:textStyle="bold" /> 
</RelativeLayout>