Как разделить экран на три панели разного размера в Android? - PullRequest
1 голос
/ 21 марта 2012

Я хочу создать такой экран на Android:

<img src="https://i.stack.imgur.com/Gq3Gu.png" alt="enter image description here">
и, добившись этого, я пишу несколько таких кодов ... Но я не делал то, что хотел.Текстовая область не существует на экране.Что я должен делать ?Любое мнение .. заранее спасибо ..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout123" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:weightSum="1.0"
        android:gravity="fill">

    <LinearLayout
        android:id="@+id/linearLayout12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top" >

     <Button android:id="@+id/button1"              
         android:layout_width="wrap_content"                                          
         android:layout_height="wrap_content"           
         android:text="Hello, I am a Button" />

        </LinearLayout>


    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="118dp"
        android:layout_height="fill_parent"
        android:layout_gravity="right"
        android:orientation="vertical" >

         <Button android:id="@+id/button2"              
         android:layout_width="wrap_content"                                          
         android:layout_height="wrap_content"           
         android:text="Hello, I am a Button" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="228dp"
        android:layout_height="fill_parent"
        android:layout_gravity="left" >

           <TextView 
                android:id="@+id/text2"              
                android:layout_width="wrap_content"             
                android:layout_height="wrap_content"              
                android:text="Hello, I am a TextView" />

           </LinearLayout>


    </LinearLayout>

Ответы [ 2 ]

6 голосов
/ 21 марта 2012

RelativeLayout выполнит то, что вы хотите

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

     <LinearLayout
        android:id="@+id/rightLayout"
        android:layout_width="100dip"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:background="#003300"
        android:orientation="vertical" >
    </LinearLayout>


    <LinearLayout
        android:id="@+id/topLayout"
        android:layout_toLeftOf="@id/rightLayout"
        android:layout_width="fill_parent"
        android:layout_height="100dip"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="#330033"
        android:orientation="vertical" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottomLayout"
        android:layout_toLeftOf="@id/rightLayout"
        android:layout_below="@id/topLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:background="#334433"
        android:orientation="vertical" >
    </LinearLayout>

</RelativeLayout>

Результат в виде LinearLayouts и Buttons / TextViews (поскольку я не был уверен, что вы хотели):

Result Result2

Если вы используете LinearLayouts в качестве контейнера для хранения нескольких представлений, оставьте его как есть.

Если вы планируете иметь только один вид в каждой из ваших «частей», измените LinearLayouts в моем файле макета на этот тип. Ex. если вы хотите, чтобы часть 1 была просто изменением кнопки

<LinearLayout
        android:id="@+id/topLayout"

будет

<Button
        android:id="@+id/topLayout"

Вложенные представления плохие, поэтому хорошо избегать их, если вы можете

2 голосов
/ 21 марта 2012

вы могли бы:

Main linear layout with vertical alignment
add a new linear layout with horizontal alignment
add a new linear layout with horizontal or vertical alignment

Таким образом, в первом макете (левая часть основного макета) вы добавляете новый линейный макет с горизонтальным выравниванием и добавляете два нужных элемента. Во втором макете (правая часть основного макета) вы добавляете новый линейный макет или непосредственно объект, который хотите показать

...