【问题标题】:How to divide screen into three parts vertically?如何将屏幕垂直分成三部分?
【发布时间】:2012-08-12 21:51:17
【问题描述】:

我的屏幕上有ScrollView 和三个不同的LinearLayouts

一个LinearLayout 包含一个Spinner,第二个包含ListView,第三个包含两个Buttons(水平)。

我想显示一个屏幕,其中包含始终显示在屏幕底部的 3 个LinearLayouts 和始终显示在顶部的 1 个 LinearLayout。在中间部分,我想显示ListView 内容。这样整个屏幕上就没有空白了。

我想为多个不同尺寸的设备创建屏幕。

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

<include
    android:id="@+id/include1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    layout="@layout/actionbar" >
</include>

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="10dp" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight=".2"
            android:background="@drawable/rounded_border"
            android:orientation="vertical"
            android:padding="15dp" >

            <TextView
                android:id="@+id/tvDiaryData"
                style="@style/greenstyle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/heading"
                android:gravity="center_horizontal"
                android:text="@string/tvDiaryData" >
            </TextView>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="10dp"
                android:gravity="center_horizontal" >
            </TextView>

            <Spinner
                android:id="@+id/spDiaryAllBooking"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:prompt="@string/select_diaryallbooking" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.6"
            android:background="@drawable/layerlist"
            android:orientation="vertical"
            android:paddingBottom="5dp"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:paddingTop="5dp" >

            <ListView
                android:id="@+id/lvDiaryBooking"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:divider="#636466"
                  android:layout_weight="1"
                android:dividerHeight="1dip"
                android:scrollbarStyle="outsideOverlay"
                android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight=".2"
            android:background="@drawable/rounded_border"
            android:orientation="horizontal"
            android:padding="10dp" >

            <Button
                android:id="@+id/btnDiaryBook"
                style="@style/greenButton"
                  android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"                    
                android:onClick="btnDiaryBook_Click"
                android:text="@string/btnBook" >
            </Button>

            <Button
                android:id="@+id/btnDiaryBalance"
                style="@style/greenButton"
                  android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_marginLeft="10dp"                 
                android:onClick="btnDiaryBalance_Click"
                android:text="@string/btnDiaryBalance" >
            </Button>
        </LinearLayout>
    </LinearLayout>
         </ScrollView>

     </LinearLayout>

我想要的屏幕布局:

【问题讨论】:

    标签: android android-layout android-intent android-emulator android-widget


    【解决方案1】:

    这是一个非常简单的解决方案。您应该可以在当前布局中使用它。

    只需使用您想要的内容填充LinearLayouts

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <LinearLayout
            android:id="@+id/ll1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/ll2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/ll3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >
        </LinearLayout>
    
    </LinearLayout>
    

    上面发布的代码的屏幕截图,颜色显示了不同的布局区域。

    【讨论】:

    • 两次编辑 - 使用“fill_parent”而不是“match_parent”并尝试将您尝试标准化的尺寸设置为“0dp”...在这种情况下,layout_height="0dp" 而不是 layout_height= “fill_parent”
    • @edthethird 很确定 fill_parent 已被弃用,您仍应使用 match_parent。他们做同样的事情。
    猜你喜欢
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多