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 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划