在Android布局文件中,我有一个按钮。我想为按钮显示一个没有任何文本的图像。我的问题是,图像被拉伸以覆盖整个按钮区域。我不想将其拉伸,而是希望将按钮放置在按钮的中央,而图像不会变形。
<Button
android:layout_width="38dp"
android:layout_height="match_parent"
android:background="@drawable/icon_more"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
现在,它看起来像这样:
它是水平拉伸的,这不是我想要的。
使用ImageButton是您的另一选择。你可以试试:
<ImageButton
android:layout_width="38dp"
android:layout_height="match_parent"
android:src="@drawable/icon_more"
android:scaleType="centerInside"
/>
灵活结合使用layout_width,layout_height和scaleType属性可帮助您获得良好的UI
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句