繁体   English   中英

Android布局百分比/比例调整

[英]Android Layout Percentage/Proportion Resize

我有3种布局。 第一个和第三个是RelativeLayout,中间的是TableLayout。 我想要的是TableLayout应该覆盖80%的屏幕。 其余的占10%。 我该怎么办? android:layout_weight对我没有帮助。 请您为该解决方案输入代码?

好的,这是一些步骤:

  • 设置为android:layout_width的相对和表格布局为0dp
  • 在父布局中将android:weightSum添加到10
  • 在3个子布局的每一个中,添加android:layout_weight并将第一个和第三个设置为1,将中间表布局设置为8。

这是代码和屏幕截图:

图形编辑器视图

<?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="horizontal"
    android:weightSum="10" >

    <RelativeLayout
        android:id="@+id/leftPane"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:background="#336699"
        android:layout_weight="1">

        <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="10% wide"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    </RelativeLayout>

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="8">

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent" 
                android:background="#00FFFF">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="row 1" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#33FFFF" >

                                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="row 2" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#66FFFF" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="row 3" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#99FFFF" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="row 4" />

            </TableRow>

        </TableLayout>

    <RelativeLayout
        android:id="@+id/rightPane"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:background="#336699"
        android:layout_weight="1">

        <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="10% wide"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    </RelativeLayout>

</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM