Android编程入门-第7天
2018-03-11 08:53
267 查看
今天学习了设备旋转后的布局有关内容,依然需要编辑activity_quiz.xml文件。
需要用到FrameLayout来替换最上层的LinearLayout,并在Textview、LinearLayout、Button中都加入android:layout_gravity的属性,其中,LinearLayout中的Button子元素保持不变。
具体实现代码如下:<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/question_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="24dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/true_button" />
<Button
android:id="@+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/false_button" />
</LinearLayout>
<Button
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:text="@string/next_button"
android:drawableRight="@drawable/arrow_right"
android:drawablePadding="4dp" />
</FrameLayout>效果如图所示:
需要用到FrameLayout来替换最上层的LinearLayout,并在Textview、LinearLayout、Button中都加入android:layout_gravity的属性,其中,LinearLayout中的Button子元素保持不变。
具体实现代码如下:<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/question_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="24dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/true_button" />
<Button
android:id="@+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/false_button" />
</LinearLayout>
<Button
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:text="@string/next_button"
android:drawableRight="@drawable/arrow_right"
android:drawablePadding="4dp" />
</FrameLayout>效果如图所示:
相关文章推荐
- Android: NDK编程入门
- Android: NDK编程入门笔记
- Android开发菜鸟级入门5--网络编程之套接字TCP
- Android传感器编程入门(三)
- Android 网络编程 初级入门(一)
- Android传感器编程入门
- Android编程入门之HelloWorld项目目录结构分析
- android ndk jni 编程入门例子
- Android: NDK编程入门笔记
- Android: NDK编程入门笔记
- Android 入门到精通 (界面编程#2-Menu)
- Android: NDK编程入门笔记
- Android 入门到精通 (三)(界面编程#1-从Button说起)
- Android手机摄像头编程入门
- Android 4编程入门经典pdf
- Android编程入门--Button圆角样式
- Android开发菜鸟级入门4--网络编程之套接字UDP
- OpenGL ES 入门 (二) OpenGL ES编程模型:模拟—— 译自《Beginning Android Games》
- 《Delphi XE6 android 编程入门教程》推荐
- Android手机摄像头编程入门