Aligning images about right bottom corner

♀尐吖头ヾ 提交于 2019-12-22 09:59:32

问题


I am using relative layout to superimpose one smaller image on top of a larger one. I want the bottom-right corner of the smaller image to coincide with B-R corner of the larger image. I'm using margin parameters in my layout XML (specifying measurement in dips) but this doesn't seem to work for all devices and resolutions - in some cases the small image is shifted by 4-5px from the border.

Is it possible to specify the position of the smaller image without pixel values? I.e. with gravity or something?


回答1:


<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:id="@+id/big_image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/bigimage"/>
    <ImageView
        android:id="@+id/little_image"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:layout_alignRight="@id/big_image"
        android:layout_alignBottom="@id/big_image"
        android:src="@drawable/littleimage"/>
</RelativeLayout>

Nice thing about RelativeLayout is that you can use relative positions and dimensions, instead of using specific dips or pixels. In the case above, I just played with the android:layout_align* parameters, to make sure that both images are aligned. Keep in mind that I set a specific dimension of the little image, but you can change that to fit your needs.



来源:https://stackoverflow.com/questions/4079410/aligning-images-about-right-bottom-corner

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