Android 在滑动抽屉中布置2排3个按钮
这是我开发安卓系统的第五天,所以要温柔 我正在尝试将两行三个按钮放入我的Android 在滑动抽屉中布置2排3个按钮,android,android-linearlayout,android-relativelayout,slidingdrawer,Android,Android Linearlayout,Android Relativelayout,Slidingdrawer,这是我开发安卓系统的第五天,所以要温柔 我正在尝试将两行三个按钮放入我的滑动抽屉,这是我目前所拥有的,但我不明白为什么第二行按钮不可见 <SlidingDrawer android:id="@+id/SlidingDrawer" android:layout_width="fill_parent" android:layout_height="200dip" android:content="@+id/drawerButtons" android:h
滑动抽屉
,这是我目前所拥有的,但我不明白为什么第二行按钮不可见
<SlidingDrawer
android:id="@+id/SlidingDrawer"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:content="@+id/drawerButtons"
android:handle="@+id/slideHandleButton" >
<Button
android:id="@+id/slideHandleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/closearrow" />
<RelativeLayout
android:id="@+id/drawerButtons"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#80000000" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Test1" >
</Button>
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Test2" >
</Button>
<Button
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Test3" >
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/Button04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Test4" >
</Button>
<Button
android:id="@+id/Button05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Test5" >
</Button>
<Button
android:id="@+id/Button06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Test6" >
</Button>
</LinearLayout>
</RelativeLayout>
</SlidingDrawer>
第一行按钮按预期显示,但我看不到第二行?只是一片空白
感谢您提供的任何帮助您在RelativeLayout中删除了两个线性布局,但没有给出布局应如何放置元素的任何提示。因此,默认情况下,两个LinearLayout将在RelativeLayout内的(0,0)处彼此重叠渲染 一种解决方案是为顶层线性布局提供一个id
android:id="@+id/topRow"
然后给线性布局一个提示,把它自己放在相对位置
android:layout_below="@id/topRow"
除此之外,您还必须将两个线性布局的布局高度设置为包裹内容。否则,第一个线性布局仍将填充整个RelativeLayout,另一个放置在屏幕外部下方
其他解决方案:将LinearLayout包裹在方向垂直的LinearLayout内,或使用GridLayout(>=API级别14)。您还可以尝试减少视图树,只使用一个RelativeLayout,并使用下面的layout_、layout_leftOf、。。。要将元素放置在布局中。请尝试以下代码:
try this below code :
<LinearLayout
android:layout_width="fill_parent"
android:id="@+id/drawerButtons"
android:orientation="vertical"
<LinearLayout>
// your buttons
</LinearLayout>
<LinearLayout>
// your buttons
</LinearLayout>
</LinearLayout>
谢谢这个pocmo!我只是假设,在另一个布局构件中放置两个线性布局时,它们会一个接一个地堆叠。我将按照您的建议使用RelativeLayout。关于此布局的另一个快速问题是,我现在看到两行按钮,但在我的滑动抽屉底部有一个空白区域。为什么RelativeLayout没有填满容器?RelativeLayout正在填满容器,但里面没有更多的东西可以显示?尝试为不同的布局提供不同的背景颜色(例如,android:background=“#ff0000”表示红色),这样更容易看到发生了什么。你期望的行为是什么?按钮的高度填满了整个空间?是的,我想让两个线性布局均匀地填满相对位置,这样所有六个按钮都占据了整个滑动抽屉区域,我是否需要再次嵌套线性布局来实现这一点?