【发布时间】:2017-11-14 22:44:10
【问题描述】:
我正在尝试使用 layout_weight 实现一个垂直分隔屏幕 40/60 的布局。
这里是xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@drawable/background">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.4">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.6">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/black" />
</LinearLayout>
</LinearLayout>
此代码不起作用,返回一个空白屏幕。但是,如果我改变了
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
(垂直分割)
到
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.4"
(水平分割)
代码按预期工作,布局水平拆分为 40/60。为什么它不能垂直工作,我该如何解决这个问题?任何帮助将不胜感激!
【问题讨论】:
-
将父布局方向设置为垂直
-
@Anmol Strange,我可以发誓我试过了,但它没有用......不过还是谢谢你!另外,您介意回答问题而不是回复,以便我可以将此帖子标记为已回答吗?
-
当然欢迎