JonSkeet 2013-08-29 06:19 采纳率: 0%
浏览 2072

显示嵌套的 LinearLayout 时的错误

我在xml文件中使用嵌套的 LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="left"
   android:layout_weight="1"
   android:layout_gravity="left"
   android:id="@+id/previous"></Button>
   <TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_weight="1"
android:gravity="center"
android:id="@+id/date"
android:textColor="#505050"
/>  
<Button android:text="right"
android:layout_weight="1"
android:layout_gravity="right"
   android:id="@+id/next"></Button>
</LinearLayout>
.........
........
</LinearLayout>  

程序不能开启,错误显示说程序意外停止。尽管没有在 Linearlayout中运行。大家有什么意见呢?

  • 写回答

1条回答 默认 最新

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-01-13 21:17
    关注

    这个错误可能是由于您在嵌套的 LinearLayout 中使用了 layout_width 和 layout_height 属性。


    当 LinearLayout 的 orientation 设置为 horizontal 时, layout_height 应该设置为 wrap_content,而 layout_width 应该设置为 fill_parent。


    反之,当 LinearLayout 的 orientation 设置为 vertical 时, layout_width 应该设置为 wrap_content,而 layout_height 应该设置为 fill_parent。


    您可以尝试将第一个 LinearLayout 中的 layout_width 和 layout_height 改为 wrap_content,然后在其他LinearLayout中重新调整,或者使用其他布局类型,如 ConstraintLayout 来解决问题。

    评论

报告相同问题?

悬赏问题

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