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 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题