开发者

Android - Image button size

开发者 https://www.devze.com 2023-01-13 01:54 出处:网络
My imagebutton code wont respond to \"fill_parent\" and \"wrap_content\". Instead, it just shows the middle of the image (because it is a pretty big image).

My imagebutton code wont respond to "fill_parent" and "wrap_content". Instead, it just shows the middle of the image (because it is a pretty big image). I tried setting specific values for the image but it still didn't work! Can somebody help me?

My button.xml in the res/drawable folder:

<?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>

My main.xml in the res/layout folder:

<?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>

I 开发者_如何学Ctried using a LinearLayout, but the app wouldnt run, and I tried replacing the imagebutton with an imageview, but then the button didn't work.


If your image is bigger than your button, you will need to use something like android:scaleType or setMaxHeight() to have it resize to fit.

Also, I recommend that you have all images in your <selector> be the same size, at least until you get things working the way you wish.

0

精彩评论

暂无评论...
验证码 换一张
取 消