Ete_ghost 2015-05-25 09:08 采纳率: 0%
浏览 2708

Android xml布局 weight 问题

在下面的代码中,Android studio提示
Layout weights require a widget to be measured twice. When a LinearLayout
with non-zero weights is nested inside another LinearLayout with non-zero
weights ,then the number of measurements increases exponently.
这要怎么改?

//这段是从一段里截取的

   <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <Button
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:text="@string/again"
            android:id="@+id/again"
            android:layout_weight="1"/>

        <Button
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:text="@string/confirm"
            android:id="@+id/confirm"
            android:layout_weight="1" />
    </LinearLayout>
  • 写回答

8条回答 默认 最新

  • 存在感在哪里 2015-05-25 09:18
    关注

    你就一个LinearLayout,你怎么用weight属性呢,两个button有一个父LinearLayout,此LinearLayout有宽度故可以用weight。如果你的LinearLayout也有父节点,就可以用weight。
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <!--设置高度,去掉weight-->

        <Button
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:text="@string/again"
            android:id="@+id/again"
            android:layout_weight="1"/>
    
        <Button
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:text="@string/confirm"
            android:id="@+id/confirm"
            android:layout_weight="1" />
    </LinearLayout>   <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    
        <Button
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:text="@string/again"
            android:id="@+id/again"
            android:layout_weight="1"/>
    
        <Button
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:text="@string/confirm"
            android:id="@+id/confirm"
            android:layout_weight="1" />
    </LinearLayout>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决