0

I'm using two buttons in my list. One is a ToggleButton and the other is a regular ImageButton

Here is how I've set it in the XML:

    <ToggleButton android:id="@+id/favc"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:background="#ffffff"
        android:padding="15dp"
        android:layout_gravity="center"
        android:focusable="false"
        android:layout_marginRight="10dp"
        android:textOn="" android:textOff=""
        />


    <ImageButton
        android:id="@+id/edit"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#ffffff"
        android:gravity="center"
        android:focusable="false"
        android:layout_marginRight="10dp"
        android:layout_alignParentLeft="true"
        android:padding="15dp"
        android:src="@drawable/pencil"/>

The logic for toggling the button is in my list adapter:

if (holder.favButton.isChecked())
    holder.favButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.star_pressed));
else
    holder.favButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.star_1));

Question/Problem

Everything works fine on a regular sized screen. However, when I test this on a tablet, the ToggleButton is really big in size compared to the ImageButton. I've verified the image size for all the res folders. This is what I have:

hdpi = 24 x 24 (pencil), 24 x 23 (star)
mdpi = 16 x 16 (pencil), 16 x 15 (star)
xhdi = 32 x 32 (pencil), 34 x 32 (star)
xxhdi = 42 x 42 (pencil), 51 x 48 (star)

This is how it looks on tablet

enter image description here

This is how it looks on normal phone

enter image description here

Instead of 32dp I've tried wrap_content as well but that did not help either.

Anthony
  • 33,838
  • 42
  • 169
  • 278
  • Did you read: http://developer.android.com/guide/practices/screens_support.html? – Phantômaxx Jun 03 '14 at 15:19
  • The small image seems low quality to me. Imagine scaling it UP! You should start with a BIG image (say xxhdpi: 480 dpi) and scale it DOWN (or just put that one in the drawable-xxhdpi folder). – Phantômaxx Jun 03 '14 at 15:21
  • what's the resolution of your tablet? because tablets use diffrent naming for folders other than -ldpi, -mdpi, -hdpi... they rather use -swMINXINDP-hMINYINDP and so on. So, it might be choosing the wrong folder where to pick images. I'd also check out that all images have the proper dpi: ldpi=120, mdpi=160, hdpi=240, all the others are mdpi*(x+1) (xhdpi=2, xxhdpi=3, xxxhdpi=4) – Phantômaxx Jun 03 '14 at 15:48
  • @DerGolem Maybe i'm missing something...but quality doesn't have anything to do with it showing so big right? I should also mention that if I simply make it an `ImageButton` and put `src` as `@drawable/star_1` then everything works fine. However, then I of course lose the `ToggleButton` which I need. IT seems like it has something to do with `ToggleButton`... – Anthony Jun 03 '14 at 15:50
  • @DerGolem this is the resolution of the tablet emulator http://cl.ly/image/1Y3T3C0y432Q – Anthony Jun 03 '14 at 15:52
  • So, it's `1280*800 @ 160 dpi (mdpi => 1px = 1dp)`. OK, according to: http://developer.android.com/guide/practices/screens_support.html, the correct drawable folder should be: (720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc)) => `/res/drawable-sw720dp`, where to copy your **mdpi** graphics. – Phantômaxx Jun 03 '14 at 15:54
  • hmmm alright. Let me create a new folder `/res/drawable-sw720dp` and put all the graphics in there and report back. – Anthony Jun 03 '14 at 16:03
  • As an alternative, you might try a resolution-specific folder: `/res/drawable-w1280dp-h800dp`. As further trials, I'd also try appending `-mdpi` to both the experimental folders (to distinguish from devices using higher resolutions, i.e.: hdpi) – Phantômaxx Jun 03 '14 at 16:12
  • So i did that, but the problem persists. All other icons except the Toggle button look ok. So, I converted `ToggleButton` to `ImageButton` and that fixes the problem (but `ToggleButton` is requirement for me). So...I'm leaning towards a problem with `ToggleButton` – Anthony Jun 03 '14 at 16:46
  • Very strange. Not a problem that I'm aware of... If your tablet uses an API Level 14+, you can use the Switch View: http://developer.android.com/reference/android/widget/Switch.html. Otherwise, you can try using a custom CheckBox – Phantômaxx Jun 03 '14 at 16:53
  • I think problem is that for `ImageButton` I am setting `src` but for `ToggleButton` I am setting `background`. Because of this the `ToggleButton` always seems bigger because its taking over the entire `background`. Is there a way around this?? just like I'm using `setBackgroundDrawable` is there a way to set the `src` of `ToggleButton`? – Anthony Jun 03 '14 at 16:54
  • BTW i am using 50dp (bigger than the image size) because I want the users to be able to click the area around the image as well. ....a way around fat finger problem. – Anthony Jun 03 '14 at 16:56
  • @DerGolem `ImageButton` seems to have `setImageXXX`, however, `ToggleButton` does not have those methods. I think I need a way to set the `src` image of the `ToggleButton` – Anthony Jun 03 '14 at 16:59
  • Wait a minute... is the problem only that of toggling the button state? If so, then simply use a state-list xml and specify the images in there. – Phantômaxx Jun 03 '14 at 17:06
  • It is not just toggling the state. it looks weird even when in normal state (nothing clicked). I asked another question that I've narrowed down the problem: http://stackoverflow.com/questions/24021032/is-there-a-way-to-programmatically-set-src-image-for-togglebutton – Anthony Jun 03 '14 at 17:09

0 Answers0