【发布时间】:2014-01-19 19:15:27
【问题描述】:
我正在尝试在 LinearLayout 中分配权重。 虽然它适用于 ButtonView-s,但它对简单视图的作用正好相反:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FF0000" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#00FF00" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="#0000FF" />
</LinearLayout>
和
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FF0000" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#00FF00" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="#0000FF" />
</LinearLayout>
这是 ButtonView 的明确实现,使其正常工作。 但是应该在 View 中实现(以及如何)与 LinearLayout 行为一致? 非常感谢。
【问题讨论】:
-
两者的输出相同,请重新检查。
-
对我来说也是一样的输出。
-
是的,确实 - 我的自定义视图是错误的(
-
@user1986565 你想在你的问题中提出和实现什么?
标签: android android-layout android-linearlayout