android:layout\u视图权重的行为与预期相反
我试着在线性布局中分配重量。 虽然它与ButtonView-s配合使用,但对于简单视图,它的作用正好相反:android:layout\u视图权重的行为与预期相反,android,android-layout,android-linearlayout,Android,Android Layout,Android 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" >
<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>
及
正是ButtonView的巧妙实现使其正确工作。
但是,为了与线性布局行为保持一致,应该实施什么(以及如何实施)?
非常感谢。你能试着用“FrameLayout”替换“View”吗?我不认为View会被用作固定器。同样的问题困扰了我,我最终使用了一个没有文本的
TextView
我只在Eclipse的图形布局模式下看到过这个问题。在我的Galaxy S2上,该应用程序按预期运行
玩弄原始“视图”的布局权重确实会产生奇怪的效果
另一个解决方法是将
视图的布局高度
从的“0dp”
更改为的“1dp”
。我不知道为什么会修复它,但我猜测一些与零相关的深层魔法(例如,一个bug,也许是一个神奇的绦虫)。两个都有相同的输出,请重新检查。我也有相同的输出。是的,确实-但我的自定义视图是错误的(@user1986565在你的问题中,你想问什么并实现什么?可能是这样。如果我想实现我的自定义视图并扩展视图,该怎么办?为了与线性布局行为保持一致,应该实现什么?我知道它是onMeasure()。但如何实现?我已经做到了,但它不适用于权重。
<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>