Android Layout Процент / Пропорция Изменение размера - PullRequest
0 голосов
/ 14 марта 2012

У меня есть 3 макета.Первый и третий - RelativeLayout, а средний - TableLayout.Что я хочу, так это то, что TableLayout должен занимать более 80% экрана.И 10% для остальных.Как я мог это сделать?android: layout_weight мне не помог.Пожалуйста, не могли бы вы поставить код для этого решения?

1 Ответ

1 голос
/ 14 марта 2012

Хорошо, вот несколько шагов:

  • установить для относительного и табличного макетов android: layout_width to 0dp
  • в родительском макете добавить android: weightSum to 10
  • в каждом из 3 дочерних макетов добавьте android: layout_weight и установите для первого и третьего значения 1 и для среднего макета таблицы значение 8.

Вот код и снимок экрана:

graphical editor view

<?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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...