2016-03-08 47 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>