2012-06-04 62 views
0

这是我的布局XML:Android的布局 - 图像查看推离

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/main_screen" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/back" 
    android:baselineAligned="false" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/bottleImageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:layout_margin="10dp" 
     android:src="@drawable/icon_food_milk" /> 

    <ImageView 
     android:id="@+id/diaperImageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:layout_margin="10dp" 
     android:src="@drawable/icon_store_diaper" /> 

    <android.opengl.GLSurfaceView 
     android:id="@+id/glview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:layout_marginTop="60dp" 
     android:windowIsTranslucent="true" /> 

</LinearLayout> 

在实际应用中的onCreate我躲都imageviews,然后在必要时我告诉他们。但是当我这样做时,GLSurfaceView将向右移动imageview的宽度。

+0

试试这个:.... android:layout_gravity =“bottom |左“ – MAC

+0

因为你的父母android:orientation =”horizo​​ntal“将其改为垂直 –

回答

0

这是因为,您正在使用LinearLayouthorizontal方向。当您使imageViews可见时,此viewGroup中的所有视图都会尝试水平放置。如果您想使位置固定,使用RelativeLayoutalignParentBottom = true

0

你的父母布局这种情况下是线性的布局它的方向是

android:orientation="horizontal" 

这将始终处于水平位置

| | 
view1 view2.... 
| | 

改为`android:orientation =“vertical”

那么你的视图应该是

view 1 
view 2 
. 
. 
+0

如果我将它改为”vertical“,那么GLSurfaceView向下移动而不是向左移动 – Trick

+1

然后使用相对布局leftof .. –