0

I am trying to make a ScrollView with some ImageButtons.

If I create it with blank buttons it works great.

My xml is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainScreen">


<HorizontalScrollView
    android:id="@+id/filtersScroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    <LinearLayout
        android:id="@+id/filtersLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/filtro1"
            android:layout_width="64dp"
            android:layout_height="64dp"/>
        <ImageButton
            android:id="@+id/filtro2"
            android:layout_width="64dp"
            android:layout_height="64dp" />
        <ImageButton
            android:id="@+id/filtro3"
            android:layout_width="64dp"
            android:layout_height="64dp"/>
        <ImageButton
            android:id="@+id/filtro4"
            android:layout_width="64dp"
            android:layout_height="64dp"/>
        <ImageButton
            android:id="@+id/filtro5"
            android:layout_width="64dp"
            android:layout_height="64dp"/>
        <ImageButton
            android:id="@+id/filtro6"
            android:layout_width="64dp"
            android:layout_height="64dp"/>
        <ImageButton
            android:id="@+id/filtro7"
            android:layout_width="64dp"
            android:layout_height="64dp"/>
        <ImageButton
            android:id="@+id/filtro8"
            android:layout_width="64dp"
            android:layout_height="64dp"/>




    </LinearLayout>

</HorizontalScrollView>

And what I get is:

Emulation picture

But when I add a picture to the drawable folder(don't know if it matters but the picture is 2000x2000) and add it to one of the ImageButtons like so:

<ImageButton
            android:id="@+id/filtro1"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:scaleType="centerInside"
            android:src="@drawable/smiley" />

Not only can I not make the image resize to the size of the button, but the app also stops working as soon as i try to run it.

This is how the preview looks like:

buttonPreview

What am I missing? Has it something to do with the size of the source picture? I mean, I just want it to resize to the size of the button and work.

Also, what happened to the other folders that used to be in drawable/? Now you don't have to separate the images according to their size?

codeMagic
  • 44,549
  • 13
  • 77
  • 93
user3013172
  • 1,637
  • 3
  • 15
  • 26

1 Answers1

1

Has it something to do with the size of the source picture

Yes. You are using a very high resolution image, and surely it will create problem on different devices (especially on low-end device). You should either use scaled down image, or try scaling through code.

Now you don't have to separate the images according to their size

No, place images in different drawable folders according to their density (not size)

See below links:

Loading Large Bitmaps Efficiently

Displaying Bitmaps Efficiently

High resolution Image - OutOfMemoryError

Community
  • 1
  • 1