1

I have a footer, where I need to place my 3 buttons horizontally (left, center and right - like I divide the width of the screen in 3 pieces each one for each button, but with margins between the buttons). I need to put one image to cover each button, and the buttons should have the shape that my images have (not scaled). The problem I have, is that I use imagebuttons in order to put my image on each button and when I change device to see how it looks like there, I see my buttons scaled. It is so annoying and I really don't know what to do. I use weightsum. My code is this:

<RelativeLayout

    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="15dp"
    android:layout_alignParentBottom="true"
    android:background="@color/black">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="3">


        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton1"
            android:background="@drawable/image1"
            android:layout_gravity="left"
            android:layout_marginRight="20dp"
            android:layout_weight="1"/>


        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton2"
            android:background="@drawable/image2"
            android:layout_gravity="left"
            android:layout_marginRight="20dp"
            android:layout_weight="1"/>


        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton3"
            android:background="@drawable/image3"
            android:layout_gravity="right"
            android:layout_weight="1"/>


    </LinearLayout>


</RelativeLayout>

Even like that, in my current device, I have to put specific margins between the buttons in order to not see the images scaled. And I am not sure if they are scaled at the end.

I would like one solution that will make me able to have the 3 images not scaled in any device and to have the margin they should have in each device, according to the size of each device.

Thank you very much in advance!!

Mary
  • 13
  • 5
  • In the second imageButton, I have android:layout_gravity="center" in my code, and not left :) – Mary Feb 06 '16 at 15:23
  • Recommended reading: http://developer.android.com/intl/in/guide/practices/screens_support.html – Phantômaxx Feb 06 '16 at 15:25
  • Hrundi V. Bakshi thanks for the link. Do you know how I can resize my images depending on the densities I have? For example, let's say I have an image 23*56px. How will I know how many pixels*pixels I should create it again for every density? ex. ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi? Please let me know if you know, I have a big problem with that. And except from that, do you also know if it is necessary to create specific drawables for small, normal, large and xlarge screens as well? I mean it will add more to my app? – Mary Feb 06 '16 at 18:39
  • Long story short: use the scaling factor. Start from the xxxhdpi image size and scale down. – Phantômaxx Feb 06 '16 at 19:32
  • which is the scaling factor? – Mary Feb 06 '16 at 19:41
  • http://stackoverflow.com/a/18656286/2649012 – Phantômaxx Feb 06 '16 at 19:44
  • @HrundiV.Bakshi so you mean that if for example I have an image 32px*40px, my drawables will be for xxxhdpi:(32*4)px *(40*4)px, for xxhdpi:(32*3)px * (40*3)px etc? Ah, and one more question, the image I have to start with, has to be the size I want for a medium density? Meaning that I have to check my image in a medium density device to see if I like it and then I continue multipling? – Mary Feb 10 '16 at 00:29
  • @HrundiV.Bakshi one more question. I just checked one drawable on an ImageButton I have and I saw that in 420 dpi screen, it looks smaller than in xxhdpi. How that can happen? – Mary Feb 10 '16 at 00:45
  • Unclear. In which folder did you put it? and which is its size? tell me the sizes for each *dpi folder. Also tell me about this phantomatic "420 dpi screen" device – Phantômaxx Feb 10 '16 at 09:13
  • @HrundiV.Bakshi nexus 5x (5.2'', 1080*1920):420dpi, nexus 5 (5.0'', 1080*1920):xxhdpi Does it happen because of the size of the screen? – Mary Feb 10 '16 at 22:24
  • @HrundiV.Bakshi one more thing, if I like my drawable in a mdpi device, does this device have to be normal as well? (I mean in the size) I am really confused with the responsiveness. – Mary Feb 10 '16 at 23:26
  • By definition, `mdpi = normal` – Phantômaxx Feb 11 '16 at 08:49
  • @HrundiV.Bakshi which device in the android studio is normal so that I can test my images there first? – Mary Feb 22 '16 at 00:16
  • `normal`, by definition, is any **mdpi** PHONE (tablets are different beasts). The standard resolution being `480x320 px` @ `160 dpi` density. – Phantômaxx Feb 22 '16 at 07:55

0 Answers0