簡體   English   中英

布局幫助 - 相對或線性

[英]Layout help - relative or linear

我正在創建一個用於在左側顯示圖像的視圖,在右側顯示網格視圖,在屏幕底部我想要包括最后一個屏幕,下一個屏幕,刷新和主頁導航按鈕,即:

圖片| 網格視圖

imagebtn | imagebtn | imagebtn | imagebtn |

我試過以下但是失敗了嗎? 我是否需要相對視圖(雖然我也沒有嘗試過)或者我做錯了什么?

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/flowers"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

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


        <ImageView
        android:id="@+id/imageView1"
        android:layout_width="96dp"
        android:layout_height="512dp"
        android:contentDescription="@string/mainlogo"
        android:src="@drawable/talltree"
        android:gravity="top"
        />

        <GridView  
        android:id="@+id/gridView1"  
        android:layout_width="wrap_content"    
        android:layout_height="wrap_content"
        android:numColumns="3"
        android:verticalSpacing="1dp"
        android:horizontalSpacing="1dp"
        android:stretchMode="columnWidth"
        android:gravity="center"

        />

</LinearLayout> 

<LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:gravity="center"
        android:layout_gravity="center">

        <ImageButton
        android:id="@+id/imageButtona"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow_left"
        android:contentDescription="@string/game1">
        </ImageButton>


        <ImageButton
        android:id="@+id/imageButtonb"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/gamelisttwo"
        android:src="@drawable/arrow_refresh1">
        </ImageButton>

        <ImageButton
        android:id="@+id/imageButtonc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/gohome"
        android:src="@drawable/gamelistone">
        </ImageButton>

        <ImageButton
        android:id="@+id/imageButtond"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/gamelisttwo"
        android:src="@drawable/gamelisttwo" 
        android:contentDescription="@string/game2">
        </ImageButton>
</LinearLayout>

</LinearLayout>

抱歉格式化

您可以通過使用RelativeLayout和LinearLayout結合來實現您的需求

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

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/bottom"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" />

    <GridView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" />
</LinearLayout>

<LinearLayout
    android:id="@+id/bottom"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:orientation="horizontal" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button2" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button3" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button4" />
</LinearLayout>

</RelativeLayout>

在第一個LinearLayout使用它: android:orientation="vertical"

在第二個LinearLayout使用: android:orientation="horizontal"

在第三個LinearLayout使用: android:orientation="horizontal"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM