How do I keep the aspect ratio on image buttons in android?

<LinearLayout android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:id=”@+id/layoutButtons”> <com.package.SquareButton android:layout_height=”fill_parent” android:layout_width=”0dip” android:layout_weight=”1″ <ImageView android:id=”@+id/box1″ android:layout_gravity=”center” android:adjustViewBounds=”true” android:scaleType=”centerInside” android:layout_height=”wrap_content” android:layout_width=”0dp” android:layout_weight=”1″ android:layout_marginLeft=”5dp” android:layout_marginRight=”5dp”/> </com.package.SquareButton> <com.package.SquareButton android:layout_height=”fill_parent” android:layout_width=”0dip” android:layout_weight=”1″ <ImageView android:id=”@+id/box2″ android:layout_gravity=”center” android:adjustViewBounds=”true” android:scaleType=”centerInside” android:layout_height=”fill_parent” android:layout_width=”fill_parent” android:layout_marginLeft=”5dp” android:layout_marginRight=”5dp”/> </com.package.SquareButton> ……… </LinearLayout> And then add this custom button class: public class SquareButton extends LinearLayout { public SquareButton(Context context) { super(context); } public … Read more

jQuery UI Dialog – missing close icon

I am late to this one by a while, but I’m going to blow your mind, ready? The reason this is happening, is because you are calling bootstrap in, after you are calling jquery-ui in. Literally, swap the two so that instead of: <script src=”http://code.jquery.com/ui/1.10.3/jquery-ui.js”></script> <script src=”https://stackoverflow.com/questions/17367736/js/bootstrap.min.js”></script> it becomes <script src=”https://stackoverflow.com/questions/17367736/js/bootstrap.min.js”></script> <script src=”http://code.jquery.com/ui/1.10.3/jquery-ui.js”></script> 🙂 Edit … Read more

Fit Image in ImageButton in Android

I want them to cover 75% of the button area. Use android:padding=”20dp” (adjust the padding as needed) to control how much the image takes up on the button. but where as some images cover less area, some are too big to fit into the imageButton. How to programatically resize and show them? Use a android:scaleType=”fitCenter” … Read more

Can’t click on ListView row with imagebutton

Unfortunately, android:focusable=”false” android:focusableInTouchMode=”false” doesn’t work for ImageButton. I finally found the solution here. In your layout xml for those items, add android:descendantFocusability=”blocksDescendants” to the root view. It works perfectly for a ListView that has ImageButtons. According to official reference, blocksDescendants means that the ViewGroup will block its descendants from receiving focus.

Android ImageButton with a selected state?

This works for me: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <!– NOTE: order is important (the first matching state(s) is what is rendered) –> <item android:state_selected=”true” android:drawable=”@drawable/info_icon_solid_with_shadow” /> <item android:drawable=”@drawable/info_icon_outline_with_shadow” /> </selector> And then in java: //assign the image in code (or you can do this in your layout xml with the src attribute) imageButton.setImageDrawable(getBaseContext().getResources().getDrawable(R.drawable….)); //set … Read more