0

I use to have a relative layout where i use to have some ImageButtons arranged. Now because i have a lot of buttons, i though i would reduce the code size and make most of the stuff in java dynamically instead of static xml. I created a grid layout where i throw the elements ImageButtons inside along with a TextView.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50" >

<TextView
    android:id="@+id/text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"/>

<ImageButton
    android:id="@+id/button_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/text_view"
    android:layout_centerHorizontal="true"
    android:src="@drawable/play_button" />
</RelativeLayout>

i Extended the BaseAdapter and pass a list with the items to fill the gridview. It works ok, but the buttons used to look different (background color):

before - after

Also the wrap_content attribute is a bit off, since it cuts off a bit of the edges on the bottom and on the right. Any idea what can cause this?

4
  • use ImageView if u don't have any text with it.it might solve ur problem. Feb 22, 2014 at 18:50
  • set android:scaleType to ImageButton
    – M D
    Feb 22, 2014 at 18:52
  • @Manmohan using ImageView is avoiding the problem, i would like to know why this happens..! but if i cannot find out why i'll revert to this option.
    – tk66
    Feb 22, 2014 at 20:19
  • @MD doesn't seem to do anything.. Also, why is the color different?
    – tk66
    Feb 22, 2014 at 20:20

1 Answer 1

0

Solved it! The problem was that when i was creating my custom fragmentPagerAdapter that contained the buttons, i was passing the context retrieved by getApplicationContext(). I switched it to getBaseContext() and now works as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.