[英]Image is stretching in imagebutton as per width and height
This ImageButton is clickable. 此ImageButton是可单击的。 I need to present this icon in center without stretch.
我需要在中间显示此图标,而无需拉伸。 Is there any way to add width and height or property?
有什么方法可以增加宽度和高度或属性? Please give me a idea.
请给我一个主意。 Thanks
谢谢
<ImageButton
android:layout_width="60dp"
android:layout_height="wrap_content"
android:background="@drawable/usercalltab"/>
usercalltab.xml usercalltab.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#ffdbab" />
</shape>
</item>
<item>
<bitmap android:src="@drawable/search"/>
</item>
</layer-list>
</item>
<item>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<bitmap android:src="@drawable/callme"/>
</item>
</layer-list>
</item>
</selector>
try like this: 尝试这样:
<ImageButton
android:layout_width="60dp"
android:layout_height="wrap_content"
android:src="@drawable/usercalltab"
android:scaleType="centerInside"
/>
or maybe android:scaleType="center"
或
android:scaleType="center"
one of those should be what you are looking for I think 我认为其中之一应该是您要寻找的
I think you should split it into background and foreground image. 我认为您应该将其分为背景图像和前景图像。 It's much cleaner and re-usable.
它更加干净和可重复使用。
If you want to achieve it without doing so, you may try this: 如果您想要不这样做而实现,则可以尝试以下方法:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#ffdbab" />
</shape>
</item>
<item>
<bitmap android:src="@drawable/search" android:gravity="center" />
</item>
</layer-list>
</item>
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item>
<bitmap android:src="@drawable/callme" android:gravity="center" />
</item>
</layer-list>
</item>
</selector>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.