圆形背景android UI中的图标图像



我正试图在圆形背景图像中插入一个图标,但图像大小有问题。图标当前比圆圈大,如果不调整圆圈背景的大小,我似乎无法调整其大小。这是我的XML:

<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/circle_dark_grey"
android:src="@drawable/calendar_icon" />
</android.support.v7.widget.LinearLayoutCompat>

我对android UI还很陌生,所以如果有更好的方法可以做到这一点,或者如果你知道如何解决我的问题,请告诉我!

干杯

您可以采用以下两种方法:

1组图像视图填充

<ImageView
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/circle_dark_grey"
android:src="@drawable/calendar_icon" />

2你可以这样使用框架布局

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:layout_gravity="center"
android:background="@drawable/circle_dark_grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/calendar_icon" />
</FrameLayout>

最新更新