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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器