Overlapping ImageView in RelativeView

不羁岁月 提交于 2019-12-12 18:24:06

问题


As my code below shows, I've two ImageView that I would like to overlap but the bigger is systematically put below the smaller one, both is android:layout_alignParentTop set "true", I thought that would lead to an overlapping but Android keeps dislaying them one below the other.

<RelativeLayout android:id="@+id/RelativeLayout1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:gravity="center_horizontal|center_vertical">
        <ImageView android:id="@+id/homeStars" android:src="@drawable/background" 
            android:layout_height="wrap_content" android:layout_width="fill_parent" android:scaleType="centerInside" 
            android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_alignParentTop="true"  
            />
        <ImageView android:id="@+id/homeLogo" android:src="@drawable/logo"
            android:layout_height="wrap_content" android:layout_width="220dip"
            android:layout_alignParentTop="true" android:layout_centerHorizontal="true"
            android:paddingTop="2dip" />
</RelativeLayout>

Nota 1 : I do not want the first one to be set as a background of the relative view. Nota 2 : I should add that this Relative Layout is put inside a ScrollView.


回答1:


<RelativeLayout
    android:id="@+id/RelativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/homeStars"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerInside"
        android:src="@drawable/background" />

    <ImageView
        android:id="@+id/homeLogo"
        android:layout_width="220dip"
        android:layout_height="wrap_content"
        android:paddingTop="2dip"
        android:src="@drawable/logo" />

</RelativeLayout>

I removed all of you're different layout_* tags and it works fine. Naturally all children will overlap each other by positioning themselves at the top left in a RelativeLayout. You're extra tags were confusing not only me but likely the parser. Copy paste the above code and make changes incrementally next time! :)




回答2:


Try this related post. A FrameLayout will get the job done, even though you seem very keen on a RelativeLayout. Is a compromise possible for you?



来源:https://stackoverflow.com/questions/7754092/overlapping-imageview-in-relativeview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!