[英]How to divide screen with three different-sized panel in android?
我想在android上創建一個這樣的屏幕:
並實現了這一點,我寫了一些類似的代碼。。但是我沒有做我想做的。 屏幕上不存在文本區域。 我該怎么辦 ? 任何意見..提前謝謝.. <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>
一個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(因為我不確定您想要哪個):
如果您將LinearLayouts用作容納多個視圖的容器,請保留它。
如果您計划在每個“零件”中僅使用一個視圖,請將布局文件中的LinearLayouts更改為該類型。 例如 如果您希望第1部分只是一個按鈕更改
<LinearLayout
android:id="@+id/topLayout"
成為
<Button
android:id="@+id/topLayout"
嵌套視圖不好,因此最好避免使用它們
你可以 :
Main linear layout with vertical alignment
add a new linear layout with horizontal alignment
add a new linear layout with horizontal or vertical alignment
因此,在第一個布局(主布局的左側)中,您將添加一個具有水平對齊方式的新線性布局,並添加所需的兩個元素。 在第二個布局(主布局的右側)中,添加新的線性布局或直接添加要顯示的對象
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.