首页 > 解决方案 > Offsetting an overlay in Android

问题描述

I have an ImageView with a background and a src. The background is sized (for xxxhdpi) 111x111 and the src is sized (again, for xxxhdpi) as 27x34.

I would like the src image to display in the upper right, and be sized correctly (smaller) but what I am seeing now is that it centers and expands to the size of the background image.

Do I need to make the src the same size as the background and add a transparent background to the lower left perhaps?

Here is what I have so far.

<ImageView android:layout_width="80dp"
            android:layout_height="80dp"
            android:id="@+id/autoButton"
            android:background="@drawable/automode"
            android:src="@drawable/lock_icn"
            android:layout_marginBottom="15dp"
            android:textColor="@color/grey_400"
            android:text="@string/auto_mode"
    />

Thanks.

标签: android

解决方案


最终变得非常像上面提到的那样。这是为了完整性。

     <FrameLayout
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/automode"
            >

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="@string/auto_mode"
                android:textColor="@color/grey_400"
                android:textSize="17sp" />

        <ImageView android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_gravity="end"
                android:id="@+id/deleteButton"
                android:src="@drawable/lock_icn"
                />
    </FrameLayout>

推荐阅读