Android 使用LinearLayout拆分屏幕时出现的问题
我在使用线性布局拆分屏幕时遇到问题, 我的目标是把它分成9个双鱼座- 当我开始玩线性布局时,我得到了以下结果: 使用以下xml代码:Android 使用LinearLayout拆分屏幕时出现的问题,android,android-layout,Android,Android Layout,我在使用线性布局拆分屏幕时遇到问题, 我的目标是把它分成9个双鱼座- 当我开始玩线性布局时,我得到了以下结果: 使用以下xml代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:baselineAligned="false">
<FrameLayout
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1">
</FrameLayout>
<FrameLayout
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="4"/>
<FrameLayout
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
后来,当我尝试向左侧FrameLayout添加内容时,它更改了此FrameLayout的比率(这就是问题所在..):
使用以下代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:baselineAligned="false">
<FrameLayout
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="row one"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row two"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row three"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row four"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="4"/>
<FrameLayout
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
我想有能力控制布局只是与布局的重量属性-如果添加内容到FrameLayout改变其比率,我需要你的帮助找到另一个容器,该比率将保存在。
谢谢。哇,你使用了很多嵌套布局!您的左手布局是否需要是一个框架布局,其中包含另一个线性布局,然后是所有文本视图?或者您可以只替换FrameLayout父对象并将背景色移动到垂直线性布局吗 实际上,为什么你也需要第二个线性布局呢?您只需指定第一个线性布局的方向为水平(在高度上仍有填充父对象),然后放置第二个嵌套线性布局
还应该考虑将框架布局的宽度更改为0DP,以便根据权重动态调整大小。