gpt4 book ai didi

android - 嵌套布局的问题

转载 作者:行者123 更新时间:2023-11-30 04:48:04 30 4
gpt4 key购买 nike

我刚刚开始使用 Android,却陷入了困境。我做了一个简单的应用程序/ View 。这个想法是在顶部画一个迷宫,在底部画一个运动按钮。我的应用程序只在框架中绘制了带有几条线的 x,但它确实有效。问题是我的按钮画得太低了,高度被剪掉了。

我认为问题出在我的布局 xml 中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >

<none.maze.MazeView
android:id="@+id/maze"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/text"
android:text="@string/maze_layout_text_text"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:textColor="#ff8888ff"
android:textSize="24sp"/>
</RelativeLayout>

</FrameLayout>

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

<Button
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left"
android:layout_weight="1"
/>

<Button
android:id="@+id/forward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forward"
android:layout_weight="1"
/>

<Button
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right"
android:layout_weight="1"
/>

</LinearLayout>

</LinearLayout>

最佳答案

我认为你不应该同时使用 layout_height="fill_parent"layout_weight。尝试为 FrameLayoutlayout_height="wrap_content" 设置 layout_height="0dip"layout_weight="1" > 用于较低的 LinearLayout。较低的 LinearLayout 不得具有 layout_weight 属性。

关于android - 嵌套布局的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4328151/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com