Android - 图片按钮大小
问题描述:
我的imagebutton代码不会响应“fill_parent”和“wrap_content”。 相反,它只是显示图像的中间(因为它是一个非常大的图像)。 我尝试设置图像的特定值,但它仍然无法使用!有人能帮助我吗?Android - 图片按钮大小
我在res /文件夹绘制button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">\
<item android:state_pressed="true"
android:drawable="@drawable/largishbutton" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/largerbutton2" /> <!-- focused -->
<item android:drawable="@drawable/largerbutton" /> <!-- default -->
</selector>
我在res /布局文件夹中的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white">
<ImageButton
android:src="@drawable/button"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
/>
</RelativeLayout>
我尝试使用的LinearLayout,但应用程序难道不运行,我尝试用imageview替换imagebutton,但是然后按钮不起作用。
答
如果您的图片比您的按钮大,您需要使用诸如android:scaleType
或setMaxHeight()
之类的东西来调整其大小。
此外,我建议您将<selector>
中的所有图片放在相同的大小,至少在您按照自己的意愿按照您的要求操作之前。