Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale Images in Different Resolutions XML

I have created 4 resolution folders and put the appropriate image sizes into each as seen in the picture below:

enter image description here

I have also created 8 different layout folders for various screen sizes as seen in the picture below:

enter image description here

As you can see in the picture below, I need to re-size the images in each according XML file so they fill the screen:

enter image description here

I use this code to scale down images which works fine:

android:adjustViewBounds="true"  
    android:maxWidth="150dp" 
    android:scaleType="fitCenter"

But I cannot figure out how to scale up images. I have been trying to use this code:

android:adjustViewBounds="true"  
    android:minWidth="150dp" 
    android:scaleType="fitCenter"

Any ideas on how to scale up the images? Thank you!!

XML:

    <ImageButton
    android:id="@+id/btnPlay"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/imageView1"
    android:layout_marginTop="15dp"
    android:background="@null"
    android:src="@drawable/btn_play"
    android:adjustViewBounds="true"  
    android:scaleX="1.5"
    android:scaleY="1.5"
    android:scaleType="fitXY"  />
like image 885
Shane Avatar asked Jul 25 '13 04:07

Shane


People also ask

What is XML scale type?

ScaleType is used for uniformly scaling the image bounds to the ImageView. Android ImageView provides various types of ScaleType for different configurations.

What is adjustViewBounds?

android:adjustViewBounds—If set to true, the attribute adjusts the bounds of the ImageView control to maintain the aspect ratio of the image displayed through it. android:resizeMode—The resizeMode attribute is used to make a control resizable so we can resize it horizontally, vertically, or around both axes.


2 Answers

Have you tried?:

android:scaleX="1.5" // 1 is 100% size
android:scaleY="1.5"
like image 152
Cԃաԃ Avatar answered Nov 04 '22 08:11

Cԃաԃ


try android:scaleType="fitXY" instead of android:scaleType="fitCenter"

Edit

use LinearLayout with layout_weight and weightSum

like adjust WeighSum and layout_weight according to your UI !

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="8" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3" >

        <!-- your Match m Image -->
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:background="#fff" >

        <!-- your play image -->
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <!-- your Multiplayer image -->
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <!-- your High score Image -->
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <!-- your how to play Image -->
    </LinearLayout>
</LinearLayout>
like image 22
Tarsem Singh Avatar answered Nov 04 '22 09:11

Tarsem Singh