imagebutton

Android: how to set the height/width of the src image of a ImageButton?

我们两清 提交于 2019-12-04 17:57:56
问题 Android: how to set the height/width of the image(src image intead of the background) of a ImageButton? I want to set the height/width of the top level image(not the background) image, the size of image should be customized instead of fullfill the button automatically 回答1: You can just Use the scaleType attribute of ImageButton . Set it to fitXY or fitCenter or anything else according to your need. like this <ImageButton android:id="@+id/imageButton" android:layout_width="100dp" android

How to use a selector to change an ImageButton image?

耗尽温柔 提交于 2019-12-04 15:42:01
How do I make an ImageButton image change its image when you press it? I hope you find this helpful. This can all be done in the XML. 1) Import your images for both pressed and unpressed states into the res/drawable- whichever folder 2) Make your selectors. Right click on a drawable folder and select New/Android xml file. Put in the name eg "ok_button_selector.xml" and choose "selector" as the root element from the menu below. You will need to create a different selector for each button on the screen. 3) In each selector file you need to define the image that will display when clicked, like

Imagebutton change programmatically?

▼魔方 西西 提交于 2019-12-04 14:56:34
问题 I'm trying to change the image of the ImageButton programmatically. I'm trying to copy this code, but the setBackgroundDrawable is already deprecated. public void giveClue(View view) { Drawable replacer = getResources().getDrawable(R.drawable.icon2); ((ImageButton) view).setEnabled(false); ((ImageButton) view).setBackgroundDrawable(replacer); gameAdapter.giveClue(game); } My button was created using xml as follows: <ImageButton android:id="@+id/ImageButton2" android:layout_width="24dp"

how to change the image of a button with every click?

喜欢而已 提交于 2019-12-04 12:00:09
问题 I created a button in the layout . In the Drawable folder I created a XML file named btn01_state . The btn01_state.xml is assigned to the button i created through " android:background=@drawable/btn01_state " Now, the button has a default image img1.when i click on the button , the image1 changes to img2, and once i release the clicked mouse button, the image2 again changed to img1 again. what i want to do is,to change the image of the button with evey click. for an example, initially btn01

Imagebutton full image, round corners

爱⌒轻易说出口 提交于 2019-12-04 07:52:15
Well.. I have some ImageButtons in my Android application. I want them to display the full picture. I mean: I want the ImageButton to be JUST the picture, you know? Ok... so far, so good... I can do it use the property "background". However I also want the ImageButton to have the corners rounded. I have the following xml in my layout folder: <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FFFFFFFF"/> <corners android:radius="10dip"/> <stroke android:width="8dip"/> <size android:height="8dip"/> </shape> It works

Android - different image for rollover on ImageButton

☆樱花仙子☆ 提交于 2019-12-04 06:07:50
Is it possible to specify a different image when the user's focus comes to an ImageButton? I want to display an image button on a LinearLayout and change the image when the user's focus comes on the button or when the user presses the button. Thanks. Yes, you can do this. What you need is a drawable xml file that defines a selector. <selector xmlns:android... <item android:state_enabled="false" android:state_focused="true" android:drawable="..." /> <item android:state_enabled="true" android:state_focused="false" android:drawable="..." /> </selector> Then, use the id of this drawable XML when

Rows don't render properly in Android Layout. Buttons seem to be the problem

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 05:33:54
问题 I am new to Android Development and I am having trouble with my XML Layout... when I inly have rows with text and edittext the layout stays ok, but once I put the row with the buttons the lower rows just disappear below the screen and the rows render way apart from each other... what am I doing wrong? The iPhone version of my app shows the layout I am trying to achieve... http://itunes.apple.com/br/app/my-food-calc/id385519343?mt=8 Thank You, very much! <ImageView android:id="@+id/imageView1"

How to make ImageButtons bounds wrap around the image?

梦想的初衷 提交于 2019-12-04 04:37:15
问题 I'm making a GUI for an android app, this GUI contains a four direction ImageButtons (look at the following image): but when trying to make that always fails because a square reserved for each image, and that's what i reached : and that's my XML code : <LinearLayout android:id="@+id/circle" android:layout_weight="4" android:orientation="vertical" android:layout_marginTop="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" > <LinearLayout android:layout_width="wrap

How to add a text under the image button in Android?

て烟熏妆下的殇ゞ 提交于 2019-12-04 03:43:22
I want to add text under a image button, which are also clickable, and will be redirected to the same activity as the image button. basically it's like the app list in any android phone, e.g. If you have your ImageButton declared in XML, then just put it into a LinearLayout which also contains a TextView and set the onClickListener on the LinearLayout . The structure would be like <LinearLayout ... > <!-- This is the LinearLayout for the xml document --> <!-- Some other layout code here if you please --> <LinearLayout android:id="@+id/linLayout" ... > <ImageButton ... /> <TextView ... /> <

ImageButton: Force square icon (height = WRAP_CONTENT, width = ?)

匆匆过客 提交于 2019-12-04 03:20:55
In my horizontal LinearLayout I have a TextEdit and an ImageButton. The ImageButton is as high as the TextEdit. I'd like that the ImageButton is exactly as wide as it's long. At the moment it looks like the width of the ImageButton is like when there is no scaling (ImageButton width [px] = unscaled drawable width [px]): <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:id="@+id/txtName" android:layout_width="1dp" android:layout_height="wrap_content" android:layout_weight="1" /> <ImageButton android:id="@