2012-05-22 10 views
0

Я создаю представление, предназначенное для показа изображения слева, сетки справа и внизу экрана. Я хочу включить последний экран, следующий экран, обновить , и кнопки домашней навигации, то есть:Помощь макета - относительная или линейная

изображение | gridview

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> 

извините за форматированием

ответ

1

вы можете достигнуть ваши потребности, используя как 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> 
+0

Спасибо. Это поставило меня на правильный путь с относительной компоновкой. –

1

На первом LinearLayout используют это: android:orientation="vertical"

На втором LinearLayout используйте это: android:orientation="horizontal"

На третьем LinearLayout используйте это: android:orientation="horizontal"

+0

Я сам немного исправил это и изменил «fill_parent» на wrap_content, когда кнопки изображения выталкивались из нижней части экрана. Теперь все, что мне нужно сделать, это нажимать кнопки вниз в нижней части экрана, а не размещать их сразу после первого линейного макета (изображение плюс gridview). В конце концов, мне, возможно, придется прибегнуть к относительной компоновке. –

Смежные вопросы