Android LinearLayout - PullRequest
       1

Android LinearLayout

0 голосов
/ 23 июля 2011

Я ооочень тупо сейчас пытаюсь получить макет, который я хочу ... Я только начал с Android, и я играю с различными вариантами макета.Итак, в качестве эксперимента я хочу создать макет, который будет выглядеть так:

---------
|_______|
|   |   |
|   |   |
|   |   |
---------

Это то, что я имею до сих пор, и получаю 3 столбца, самый левый из которых - самый тонкий столбец.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/firstlayout"
              android:layout_height="fill_parent"
              android:layout_width="fill_parent">

    <LinearLayout android:layout_height="fill_parent"
                  android:layout_width="0px"
                  android:layout_weight="0.1"
                  android:background="#0000FF"
                  android:orientation="horizontal"
                  android:gravity="top">

        <TextView android:layout_height="fill_parent"
                  android:layout_width="fill_parent"
                  android:text="Top Bar"
                  android:layout_gravity="center"/>

    </LinearLayout>


    <LinearLayout android:layout_height="fill_parent"
                  android:layout_width="0px"
                  android:layout_weight="0.9"
                  android:orientation="horizontal"
                  android:gravity="bottom">

        <LinearLayout android:layout_height="fill_parent"
                      android:layout_width="0px"
                      android:layout_weight="0.5"
                      android:background="#FF0000">

            <TextView android:layout_height="fill_parent"
                      android:layout_width="fill_parent"
                      android:gravity="center"
                      android:text="Bottom Left"/>

        </LinearLayout>
        <LinearLayout android:layout_height="fill_parent"
                      android:layout_width="0px"
                      android:layout_weight="0.5"
                      android:background="#00FF00">

            <TextView android:layout_height="fill_parent"
                      android:layout_width="fill_parent"
                      android:gravity="center"
                      android:text="Bottom Right"/>

        </LinearLayout>
    </LinearLayout>


</LinearLayout>

Может кто-нибудь сказать мне, что я здесь не так делаю?

Ответы [ 3 ]

3 голосов
/ 23 июля 2011

Вы можете использовать RelativeLayout.

 <RelativeLayout
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

 <TextView
  android:id="@+id/Toptext1"
   android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  >

 <TextView
   android:id="@+id/LeftText2"
   android:layout_width="wrap_content"
  android:layout_height="fill_parent"
  android:layout_below="@id/Toptext1"/>

   <TextView
   android:id="@+id/RightText3"
   android:layout_width="wrap_content"
  android:layout_height="fill_parent"
  android:layout_below="@id/Toptext1"
  android:layout_toRightOf="@id/LeftText2"/>
</RelativeLayout>
3 голосов
/ 23 июля 2011

То, что вам нужно, это двухуровневый LinearLayout.Попробуйте это:

<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:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <!--  Views for the top row go here -->
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <LinearLayout
            android:layout_width="0px"
            android:layout_height="fill_parent"
            android:layout_weight="1">

            <!-- Views for the left column go here -->
        </LinearLayout>

        <LinearLayout
            android:layout_width="0px"
            android:layout_height="fill_parent"
            android:layout_weight="1">

            <!-- Views for the right column go here -->
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
0 голосов
/ 23 июля 2011

Чтобы разбить макет, вы должны установить android:orientation="vertical"

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/firstlayout"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
  >

<LinearLayout
    android:layout_height="0dp"
    android:layout_width="fill_parent"
    android:layout_weight="0.1"
    android:background="#0000FF"
    android:gravity="top"
>
    <TextView
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:text="Top Bar"
        android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_weight="0.9"
    android:gravity="bottom"
>
    <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="0px"
        android:layout_weight="0.5"
        android:background="#FF0000"
    >
        <TextView
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:gravity="center"
            android:text="Bottom Left" />
    </LinearLayout>
    <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="0px"
        android:layout_weight="0.5"
        android:background="#00FF00"
    >
        <TextView
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:gravity="center"
            android:text="Bottom Right" />
    </LinearLayout>
</LinearLayout>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...