rek*_*ire 11 android android-layout android-linearlayout
我正在玩这个选项measureWithLargestChild="true".我不明白为什么我的布局会断开,如果我的一个按钮上有太大的文字.我认为它应该保持1/3的基本尺寸,但它们变得小约1/6.这是为什么?
在这里你可以看到一些截图:

这是我的xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:measureWithLargestChild="true" >
<Button
style="@style/my_style"
android:layout_weight="1"
android:text="Button123456" />
<Button
style="@style/my_style"
android:layout_weight="1"
android:text="A" />
<Button
style="@style/my_style"
android:layout_weight="1"
android:text="WW" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我相信这是测量算法中的一个错误.方法中有以下评论LinearLayout.measureHorizontal(int, int).
// Either expand children with weight to take up available space or
// shrink them if they extend beyond our current bounds
Run Code Online (Sandbox Code Playgroud)
它说,weight如果没有足够的空间,算法会缩小项目.如measureWithLargestChild设置true,所有项目的宽度与最左边的项目相同.现在他们一起不再适合父母的宽度了.因此他们会缩减.如果没有错误,则之后所有项目的宽度都相同.但是由于该错误,算法缩小了原始(wrap_content)宽度而不是根据measureWithLargestChild属性计算的宽度.这就是为什么右边的两个项目变小了.
| 归档时间: |
|
| 查看次数: |
3407 次 |
| 最近记录: |