【问题标题】:Android - Image button sizeAndroid - 图片按钮大小
【发布时间】:2010-08-22 00:55:18
【问题描述】:

我的 imagebutton 代码不会响应“fill_parent”和“wrap_content”。 相反,它只显示图像的中间(因为它是一个非常大的图像)。 我尝试为图像设置特定值,但它仍然不起作用!有人可以帮帮我吗?

我在 res/drawable 文件夹中的 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/layout 文件夹中的 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,但应用无法运行,我尝试将 imagebutton 替换为 imageview,但按钮不起作用。

【问题讨论】:

    标签: android eclipse image button imageview


    【解决方案1】:

    如果您的图片比按钮大,您需要使用android:scaleTypesetMaxHeight() 之类的东西来调整大小以适应大小。

    另外,我建议您将 &lt;selector&gt; 中的所有图像都设置为相同大小,至少在您按照自己的意愿工作之前。

    【讨论】:

      猜你喜欢
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2015-10-27
      相关资源
      最近更新 更多