2012-05-22 70 views
0

我正在创建一个视图,用于在左侧显示图像,在右侧显示gridview,并在屏幕的底部显示最后一个屏幕,下一个屏幕,刷新,和家庭导航按钮,即:布局帮助 - 相对或线性

图片| 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)之后立即放置它们。毕竟,我可能不得不求助于相对布局。 –