In my case, I needed a widget with a fixed icon size. You can make your ImageButton widget as I did. Here's a snippet of what each button should look like: Use dp instead, as it is not scaled by the user's text size preference. However, it is much easier to set and preview in xml in my opinion.Īlso, do not use sp for anything other than text size, it is scaled depending on the text size preference the user sets, so your sp dimensions will be larger than your intended if the user has a "large" text setting. Use a android:scaleType="fitCenter" to have Android scale the images, and android:adjustViewBounds="true" to have them adjust their bounds due to scaling.Īll of these attributes can be set in code on each ImageButton at runtime. How to programatically resize and show them? Use android:padding="20dp" (adjust the padding as needed) to control how much the image takes up on the button.īut where as some images cover less area, some are too big to fit into the imageButton. I want them to cover 75% of the button area. IB_repeat = (ImageButton) findViewById(R.id.button_repeat) ![]() IB_next = (ImageButton) findViewById(R.id.button_next) IB_bottomright = (ImageButton) findViewById(R.id.button_bottomright) IB_bottomleft = (ImageButton) findViewById(R.id.button_bottomleft) IB_topright = (ImageButton) findViewById(R.id.button_topright) ![]() IB_topleft = (ImageButton) findViewById(R.id.button_topleft) M圜lass.java: public void addImageButtons() But where as some images cover less area, some are too big to fit into the imageButton. I have 6 ImageButton in my activity, I set images through my code in them ( not using xml).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |