首页 > 安卓ui设计底部固定问题

安卓ui设计底部固定问题

在安卓的UI设计里面碰到一个问题,当底部的两个按钮用layout_alignParentBottom时,并不会固定在底部,上面的EditText会覆盖在下面,实际如图所示:

事实上我要的是这个效果(注:EditText高度写的是固定高度)

代码如下:

<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="org.roderick.mycall.ui.main.MainActivity$PlaceholderFragment" >


<LinearLayout 
    android:id="@+id/layout_business_type"
    style="@style/sell_layout_btn_background"
    android:orientation="horizontal"
    android:gravity="center_vertical">

    <TextView
         android:id="@+id/txt_business_type"
         style="@style/sell_layout_text_style"
         android:text="@string/business_type" />

   <Spinner
       android:id="@+id/spinner_business_type"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"/>

</LinearLayout>

<LinearLayout 
    android:id="@+id/layout_business_typedetail"
    style="@style/sell_layout_btn_background" 
    android:layout_below="@+id/layout_business_type"
    android:orientation="horizontal"
    android:gravity="center_vertical"  >

    <TextView
         android:id="@+id/txt_business_typydetal"
         style="@style/sell_layout_text_style"
         android:text="@string/business_typedetail" />

    <Spinner
        android:id="@+id/spinner_business_typedetail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>



<LinearLayout
    android:id="@+id/layout_business_detail"
    style="@style/sell_layout_btn_background"
    android:layout_height="match_parent"
    android:layout_below="@+id/layout_business_typedetail">

    <EditText
        android:id="@+id/txt_business_detail"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="top"
        android:inputType="textMultiLine" 
        android:hint="@string/business_detailHint"
        />

</LinearLayout>

<LinearLayout
        android:id="@+id/layout_business_btn"
        style="@style/sell_layout_btn_background"
        android:layout_below="@+id/layout_business_detail" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:layout_alignParentBottom="true">

        <Button 
                android:id="@+id/btn_business_clear"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:layout_marginRight="5dp"
                android:background="@drawable/main_login_selector"              
                android:textColor="@color/login_txt_selector" 
                android:text="@string/business_clear"
                style="?android:attr/buttonBarButtonStyle"/>

         <Button 
                android:id="@+id/btn_business_save"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="5dp"
                android:background="@drawable/main_login_selector"              
                android:textColor="@color/login_txt_selector"                    
                android:text="@string/business_save"
                style="?android:attr/buttonBarButtonStyle"/>      

</LinearLayout>


Android在解析布局文件的时候是从上往下的。所以你要先放底部的两个Button,再放中间的EditText,并且设置EditText的上下相对位置.

<LinearLayout
        android:id="@+id/layout_business_btn"
        style="@style/sell_layout_btn_background"
        android:layout_below="@+id/layout_business_detail" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:layout_alignParentBottom="true">

        <Button 
                android:id="@+id/btn_business_clear"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:layout_marginRight="5dp"
                android:background="@drawable/main_login_selector"              
                android:textColor="@color/login_txt_selector" 
                android:text="@string/business_clear"
                style="?android:attr/buttonBarButtonStyle"/>

         <Button 
                android:id="@+id/btn_business_save"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="5dp"
                android:background="@drawable/main_login_selector"              
                android:textColor="@color/login_txt_selector"                    
                android:text="@string/business_save"
                style="?android:attr/buttonBarButtonStyle"/>   
</LinearLayout> 

<LinearLayout
    android:id="@+id/layout_business_detail"
    style="@style/sell_layout_btn_background"
    android:layout_height="match_parent"
    android:layout_below="@+id/layout_business_typedetail"
    android:layout_above="@id/layout_business_btn">

    <EditText
        android:id="@+id/txt_business_detail"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="top"
        android:inputType="textMultiLine" 
        android:hint="@string/business_detailHint"
        />
</LinearLayout>
【热门文章】
【热门文章】