0

我想在我的应用程序中遵循布局。顶部的按钮,底部的第二个按钮和第三个按钮占据整个中间空间。以下代码我正在使用 bt 它没有显示第二个按钮。如何达到效果?

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

   <Button
    android:id="@+id/button2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Save" 
     />

<Button
    android:id="@+id/button4"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="Previous" 
  />
 <Button
    android:id="@+id/button5"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"

    android:text="Next" 
   />
</LinearLayout>
4

6 回答 6

3

你可以通过Relative Layout来实现

干得好

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <!-- view=2 -->

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Save" />

    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Previous" />


    <Button
        android:id="@+id/button5"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/button4"
        android:layout_below="@+id/button2"
        android:text="Next" />


</RelativeLayout>

引用OP的第二个问题

如果在第一行有三个按钮,那么我应该在 android:layout_below 中使用什么参考

干得好

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

    <!-- view=2 -->

    <LinearLayout
        android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Save" />

        <Button
            android:id="@+id/button12"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Save" />

        <Button
            android:id="@+id/button22"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Save" />
    </LinearLayout>

    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Previous" />

    <Button
        android:id="@+id/button5"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/button4"
        android:layout_below="@+id/LinearLayout01"
        android:text="Next" />

</RelativeLayout>

它会给你以下输出

在此处输入图像描述

于 2012-06-21T12:37:52.667 回答
3
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:weightSum="1" >

    <!-- view=2 -->

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".1"
        android:text="Save" />

    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".8"
        android:text="Previous" />

    <Button
        android:id="@+id/button5"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".1"
        android:text="Next" />

</LinearLayout>

在此处输入图像描述

于 2012-06-21T12:38:25.040 回答
0
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">

           <!--view=2-->

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Save" />

<Button
    android:id="@+id/button4"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Previous" />

 <Button
     android:id="@+id/button5"
     android:layout_width="fill_parent"
     android:layout_height="match_parent"
     android:text="Next" />

</LinearLayout>
于 2012-06-21T12:36:36.687 回答
0

改为使用RelativeLayout。尝试从上到下放置按钮。

于 2012-06-21T12:37:23.400 回答
0

这是代码

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

<!-- view=2 -->

<Button
    android:id="@+id/button2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Save" />

<Button
    android:id="@+id/button5"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Next" />

<Button
    android:id="@+id/button4"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/button5"
    android:layout_below="@+id/button2"
    android:text="Previous" />

</RelativeLayout>
于 2012-06-21T12:39:16.700 回答
0

我想你必须随心所欲地尝试这个

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


   <Button
    android:id="@+id/button2"
    android:layout_weight="4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Save" 
     />

<Button
    android:id="@+id/button4"
     android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Previous" 
  />
 <Button
    android:id="@+id/button5"
     android:layout_weight="4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Next" 
   />
</LinearLayout>

如果您想更改占用的屏幕只需修改该按钮的重量,此布局会根据需要划分按钮。但我建议您改用相对布局,这会使您的工作变得轻松..

于 2012-06-21T12:44:08.147 回答