android - 安卓ui设计底部固定问题
黄舟
黄舟 2017-04-17 11:59:49
[Android讨论组]

在安卓的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>

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(1)
怪我咯

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>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号