Android 布局嵌套
2013-09-04 20:46
155 查看
本来用RelativeLayout的布局方式就很灵活,但是还是有写需求达不到。只能通过布局嵌套的方式来实现。
首先activity_main采用的是RelativeLayout布局方式,然后通过include标签引入一个LinearLayout的布局文件。
建一个xml文件,取名twobtn.xml,内容如下
<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:layout_width="0sp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/equal"/>
<Button
android:layout_width="0sp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/clear"/>
</LinearLayout>
注意以上代码中的android:layout_weight属性。
然后在主layout文件中加入以下代码
<include
android:id="@+id/btn"
layout="@layout/twobtn"
android:layout_below="@id/theTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0sp"
android:layout_marginRight="0sp"/>
首先activity_main采用的是RelativeLayout布局方式,然后通过include标签引入一个LinearLayout的布局文件。
建一个xml文件,取名twobtn.xml,内容如下
<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:layout_width="0sp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/equal"/>
<Button
android:layout_width="0sp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/clear"/>
</LinearLayout>
注意以上代码中的android:layout_weight属性。
然后在主layout文件中加入以下代码
<include
android:id="@+id/btn"
layout="@layout/twobtn"
android:layout_below="@id/theTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0sp"
android:layout_marginRight="0sp"/>
相关文章推荐
- android 开发dialog 嵌套listview布局
- Android ScrollView中嵌套RecyclerView布局显示不全或不显示终极解决方案!
- Android嵌套布局初步(二)
- Android App中的多个LinearLayout嵌套布局实例解析
- Android中多层动态嵌套布局的实现
- Android中多层动态嵌套布局的实现
- Android:LinearLayout布局和其嵌套运用举例
- Android一个布局文件嵌套另一个布局文件的方法
- Android布局管理器的嵌套
- 从零开始学android<使用嵌套布局实现计算器界面.十七.>
- Android LinearLayout布局嵌套及权重weight的使用
- Android 动态生成布局 (多层嵌套)
- Android基于基于布局嵌套的页面导航实现
- Android小知识——ScrollView内的内部嵌套LinearLayout布局导致滑动条占位置
- Android开发 详解嵌套ListView、ScrollView布局显示不全的问题
- 【Android笔记-异常-7】FrameLayout要嵌套在LinearLayout里否则布局有问题。
- Android中多层动态嵌套布局的实现
- Android中多层动态嵌套布局的实现
- Android中多层动态嵌套布局的实现
- Android嵌套布局时覆盖问题的解决