【发布时间】:2018-08-26 21:55:21
【问题描述】:
我有两个垂直线性布局,我想分别占据大约三分之一和三分之二的屏幕。我正在使用 layout_weight 来实现这一点,但它们都保持在 0dp 厚度而不是占用父级的可用宽度。
据我了解,当设置为 0dp 厚度时,这些布局应该占据
layout weighting / total weighting值得的重量。然而,这并没有发生。
这是我的 xml,第一个布局包含一个 ImageButton,第二个是空的:
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:layout_gravity="left"
android:orientation="vertical">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="false"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:srcCompat="@drawable/silhouette" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:layout_gravity="right"
android:orientation="vertical">
</LinearLayout>
【问题讨论】:
-
这两个线性布局的父级是什么?它应该是方向垂直的线性布局。子线性布局的宽度/高度也为 0,具体取决于首选方向
-
@Satya 所以他们必须在另一个垂直线性布局中才能工作?
-
是的,请检查我的回答
-
你能接受我的回答吗?
标签: android xml android-studio android-linearlayout