简体   繁体   中英

Android RelativeLayout adding layout_alignParentBottom pushing layout to the bottom of the screen

Hopefully someone can help with this RelativeLayout issue I'm having. If I remove the last ImageView from this layout the layout height is only as tall as the tallest widget (in this case it's the first ImageView). but as soon as I put the last Imageview back the layout extends to the button of the screen even pushing other layouts out of its way. I'm pretty sure its the layout_alignParentbottom attribute in the ImageView that is causing this to happen. I'm just not sure why the layout is behaving like this.

My goal is to have the RelativeLayout height only as big as the biggest widget (which is the first ImageView) but I also want the last ImageView to be align at the button of the layout. Any ideas? Thanks!

< 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>  

this is the solution I came up with which works. I've added android:layout_alignBottom="@id/image_cat" to the bottom 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"
/>

this is the solution I came up with.

< 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"
/>

Try
android:layout_alignBottom="@+id/positionImage1_cat" in first ImageView and android:layout_alignBottom="@+id/image_cat" in the second ImageView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM