Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top