2011-06-06 119 views
2

希望有人可以幫助解決我遇到的這個RelativeLayout問題。如果我從這個佈局中刪除最後一個ImageView,佈局高度只與最高部件一樣高(在這種情況下,它是第一個ImageView)。但只要我把最後一個Imageview放回去,佈局就會延伸到屏幕的按鈕,甚至將其他佈局推開。我很確定它的ImageView中的layout_alignParentbottom屬性導致了這種情況的發生。我只是不確定爲什麼佈局的行爲如此。Android RelativeLayout添加layout_alignParentBottom將佈局推送到屏幕底部

我的目標是使RelativeLayout高度只與最大的窗口部件(這是第一個ImageView)一樣大,但我也希望最後一個ImageView在佈局的按鈕上對齊。有任何想法嗎?謝謝!

< RelativeLayout 
    android:id="@+id/gallerylayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff" > 

    <ImageView 
     android:id="@+id/image_cat" 
     android:src="@drawable/img_categories_bill" 
     android:layout_alignParentRight="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
    /> 

    <TextView 
     android:id="@+id/title_cat" 
     android:layout_width="200dip" 
     android:layout_height="wrap_content" 
     android:text="...some text" 
     android:layout_alignTop="@id/image_cat" 
     android:textColor="#000000" 
     android:paddingLeft="5dp" 
     android:paddingTop="3dp" 
     /> 

    <TextView 
     android:id="@+id/description_cat" 
     android:layout_width="210dip" 
     android:layout_height="wrap_content" 
     android:text="...some text" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@id/title_cat" 
     android:textColor="#000000" 
     android:paddingLeft="5dp" 
     android:textSize="10px" 
     /> 

    <ImageView 
     android:id="@+id/positionImage1_cat" 
     android:src="@drawable/img_current" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentBottom="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="5dp" 
     android:paddingBottom="3dp" 
    />  
< /RelativeLayout> 

這是我想出了其運作的解決方案。我已經將android:layout_alignBottom =「@ id/image_cat」添加到底部ImageView。

<ImageView 
    android:id="@+id/positionImage1_cat" 
    android:src="@drawable/img_current" 
    android:layout_alignParentLeft="true" 
    android:layout_alignBottom="@id/image_cat" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="5dp" 
    android:paddingBottom="3dp" 
/> 
+0

您可以勾畫出您正在嘗試完成的任務嗎?你想要所有的textview在imageView之上? – 2011-06-06 18:31:11

+0

是的,第一個imageView作爲背景。我希望佈局的高度是第一個imageView的高度。我會看看我是否可以包括一個scetch。 – bradley4 2011-06-06 18:40:58

+0

你建立什麼API級別? API級別3粗略地支持相關佈局。 – 2011-06-06 19:04:19

回答

1

這是我想出的解決方案。

< ImageView  
android:id="@+id/positionImage1_cat"  
android:src="@drawable/img_current"  
android:layout_alignParentLeft="true"  
android:layout_alignBottom="@id/image_cat"  
android:layout_width="wrap_content"  
android:layout_height="wrap_content"  
android:paddingLeft="5dp"  
android:paddingBottom="3dp" 
/> 
0

嘗試在第一ImageView
android:layout_alignBottom="@+id/positionImage1_cat"android:layout_alignBottom="@+id/image_cat"在第二ImageView

+0

嘗試此操作時收到錯誤:RelativeLayout中不存在循環依賴項 – bradley4 2011-06-06 20:36:56