android布局自适应小示例(用户反馈界面)

要求:

1、整个界面刚好填满屏幕,不需要滚动

2、输入反馈内容的EditText控件高度能够自适应

3、提交按钮位于屏幕最下方

核心布局文件如下:

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:orientation="vertical"  
  5.     android:layout_width="fill_parent"  
  6.     android:layout_height="fill_parent">  
  7.         <TextView  
  8.             android:text="用户反馈"  
  9.             android:layout_width="fill_parent"  
  10.             android:layout_height="40dip"  
  11.             android:background="#363433"  
  12.             android:textColor="#FFFFFF"  
  13.             android:gravity="center"   
  14.             android:textSize="20sp"/>  
  15.         <LinearLayout android:orientation="vertical"  
  16.             android:layout_width="fill_parent"  
  17.             android:layout_height="fill_parent"  
  18.             android:paddingLeft="10dp"  
  19.             android:paddingRight="10dp">  
  20.             <TextView android:id="@+id/feedback_title"  
  21.                 android:layout_width="fill_parent"   
  22.                 android:layout_height="wrap_content"   
  23.                 android:textSize="19dp"  
  24.                 android:textColor="#706F6D"  
  25.                 android:layout_marginTop="10dp"  
  26.                 android:layout_marginBottom="10dp"  
  27.                 android:text="欢迎您提出宝贵的意见和建议,您的建议对我们改善服务非常有帮助。">  
  28.             </TextView>  
  29.             <LinearLayout android:orientation="horizontal"   
  30.                 android:layout_width="fill_parent"  
  31.                 android:layout_height="wrap_content"  
  32.                 android:layout_marginTop="10dp" >  
  33.                 <Spinner android:id="@+id/feedback_type_spinner"  
  34.                     android:layout_width="wrap_content"  
  35.                     android:layout_height="50dp"   
  36.                     android:layout_weight="1"  
  37.                     android:focusable="true"  
  38.                     android:entries="@array/feedback_type"/>  
  39.             </LinearLayout>  
  40.              <RelativeLayout android:layout_width="fill_parent"  
  41.                 android:layout_height="fill_parent">  
  42.                  <EditText android:id="@+id/feedback_content"  
  43.                      android:layout_width="fill_parent"  
  44.                      android:layout_height="fill_parent"  
  45.                      android:maxEms="10"  
  46.                      android:minEms="10"   
  47.                      android:hint="请输入您的反馈意见(字数500以内)"  
  48.                      android:gravity="top"  
  49.                      android:layout_marginBottom="50dip"/>  
  50.                 <Button android:id="@+id/feedback_submit"   
  51.                     android:layout_width="fill_parent"  
  52.                     android:layout_height="50dp"  
  53.                     android:text="提交反馈"  
  54.                     android:textSize="19dp"  
  55.                     android:layout_gravity="center_horizontal"  
  56.                     android:layout_alignParentBottom="true"/>  
  57.              </RelativeLayout>  
  58.         </LinearLayout>  
  59.     </LinearLayout>  

运行截图如下:


备注:

在打开的activity界面中如果包含有EditText控件,那么android默认会打开键盘输入法,但是很多时候不需要,可以通过下面的代码隐藏掉键盘:

Java代码  收藏代码
    1. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);  
原文地址:https://www.cnblogs.com/to-creat/p/5151505.html