android布局自适应小示例(用户反馈界面)
2016-01-22 15:50
441 查看
要求:
1、整个界面刚好填满屏幕,不需要滚动
2、输入反馈内容的EditText控件高度能够自适应
3、提交按钮位于屏幕最下方
核心布局文件如下:
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="用户反馈"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:background="#363433"
android:textColor="#FFFFFF"
android:gravity="center"
android:textSize="20sp"/>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView android:id="@+id/feedback_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="19dp"
android:textColor="#706F6D"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="欢迎您提出宝贵的意见和建议,您的建议对我们改善服务非常有帮助。">
</TextView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Spinner android:id="@+id/feedback_type_spinner"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:focusable="true"
android:entries="@array/feedback_type"/>
</LinearLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/feedback_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:maxEms="10"
android:minEms="10"
android:hint="请输入您的反馈意见(字数500以内)"
android:gravity="top"
android:layout_marginBottom="50dip"/>
<Button android:id="@+id/feedback_submit"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="提交反馈"
android:textSize="19dp"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
运行截图如下:
备注:
在打开的activity界面中如果包含有EditText控件,那么android默认会打开键盘输入法,但是很多时候不需要,可以通过下面的代码隐藏掉键盘:
Java代码
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
1、整个界面刚好填满屏幕,不需要滚动
2、输入反馈内容的EditText控件高度能够自适应
3、提交按钮位于屏幕最下方
核心布局文件如下:
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="用户反馈"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:background="#363433"
android:textColor="#FFFFFF"
android:gravity="center"
android:textSize="20sp"/>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView android:id="@+id/feedback_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="19dp"
android:textColor="#706F6D"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="欢迎您提出宝贵的意见和建议,您的建议对我们改善服务非常有帮助。">
</TextView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Spinner android:id="@+id/feedback_type_spinner"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:focusable="true"
android:entries="@array/feedback_type"/>
</LinearLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/feedback_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:maxEms="10"
android:minEms="10"
android:hint="请输入您的反馈意见(字数500以内)"
android:gravity="top"
android:layout_marginBottom="50dip"/>
<Button android:id="@+id/feedback_submit"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="提交反馈"
android:textSize="19dp"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
运行截图如下:
备注:
在打开的activity界面中如果包含有EditText控件,那么android默认会打开键盘输入法,但是很多时候不需要,可以通过下面的代码隐藏掉键盘:
Java代码
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
相关文章推荐
- AndroidExpandableListView实现三级列表显示
- Android 图片压缩
- Android 自定义ProgressDialog进度条对话框用法详解
- Android:可复制内容的TextView、EditText
- Android返回键的监听汇总
- Android ProgressDialog使用总结
- Android常用代码段
- Android学习历程10-Handler消息传递机制
- 关于使用Android6.0编译程序时,出现getSlotFromBufferLocked: unknown buffer: 0xac0f8650问题的解释
- android viewGroup中addView使用方式及其粗解
- android基础(六)android的消息处理机制
- Android中实现可滑动的Tab的3种方式
- android 的三种定位方式
- Android studio Github 断开连接
- 实例详解Android自定义ProgressDialog进度条对话框的实现
- GBK编码文件转UTF-8编码使用vim
- android平台硬件驱动原理学习(总)
- Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】
- activity横竖屏幕切换(解决方法)
- Android Spinner控件的简单应用