开发者

Change image on click and make it fit in an ImageView

I currently working on my personal project in Android. I'm quite a newbie in android development well it's been a months since I've started to self study this but I just can't focus on this one. Well, so here's my problem, first I will discuss what I've made so far:

I've placed a 6 ImageView for each tableRow (six table rows) in a table layout which make it a 6x6 ImageView.

each of the imageView has a default image icon (the default icon from the android drawable).

Once I clicked the ImageView I will change it's Image using setImageDrawable.

the default icon of the android is sized smaller than the images I've placed in which I think 36x36 pixels is the default icon (the android default) wherein my images are in size of 80x80 pixels.

Now here's the problem:

Once I've clicked the image it will successfully changes the image but will also resize the imageView into the size of my image(80x80 px).

well how do I get over this? I've tried setting the ImageView's scale type into fitXY but it has done nothing still my the imageView is resized.

I've also tried changing the wrap_content into fill_parent but nothing also happens (well I just think that it may solve the problem lol)

Here's the property of my ImageView:

<ImageView android:scaleType="fitXY" 
           android:id="@+id/imageView1" 
           android:src="@drawable/image0" 
           android:layout_height="wrap_content" 
           android:layout_width="wrap_content">
</ImageView>

Any help please? Thanks in ad开发者_开发问答vance!


you can set the fix size for the image view into the xml file or by coding through for e.g. here in xml file

<ImageView android:scaleType="fitXY" 
           android:id="@+id/imageView1" 
           android:src="@drawable/image0" 
           android:layout_height="90dp" 
           android:layout_width="120dp">
</ImageView>

so all image are display with the size 120*90 so when you change the picture it will fit into this imageview

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜