I defined this layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/ivSmartphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/intro_smartphone_data" />
<ImageView
android:id="#+id/ivData1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/ivSmartphone"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
android:src="#drawable/intro_data_1" />
<ImageView
android:id="#+id/ivData2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/ivData1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:src="#drawable/intro_data_2" />
<ImageView
android:id="#+id/ivData3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/ivData2"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:src="#drawable/intro_data_3" />
<ImageView
android:id="#+id/ivData4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/ivData3"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:src="#drawable/intro_data_4" />
</RelativeLayout>
It should looks like this one according to the android studio preview window:
On a Nexus5X it looks exactly like this, but on a Nexus5 i get
I thought Nexus5X and Nexus5 have the same density and take the images from the same xxhdpi directory? So what's missing?
Thanks in advance.
The size of the Nexus 5 is 360x640dp while the one of the Nexus 5X is 411x731dp while having the same density.
So when you define you layout like this
<ImageView
android:id="#+id/ivSmartphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/intro_smartphone_data" />
you're using the same image for every screen width without scaling. Instead you need to make sure to fit your images to the screen width.
<ImageView
android:id="#+id/ivSmartphone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:scaleType="fitCentered"
android:src="#drawable/intro_smartphone_data" />
fitCentered might also upscale the image. If you're fine with a bigger spacing consider using centerInside instead.
Related
So I was designing my main page for my first app, and when I emulated it I noticed that the size of my stopwatch got a little bigger for some reason. So I took my phone and tested it on there and the results aren't pretty. I used dp which I was almost certain is % and not set value so I have no clue why it changes like that.
Here is the images so it dosn't clutter my question http://imgur.com/a/IKvdI
menu1_layout.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center_horizontal">
<ImageView
android:layout_width="500dp"
android:layout_height="800dp"
android:id="#+id/imageView"
android:background="#drawable/background3" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center_horizontal">
<Button
android:id="#+id/stopWatch"
android:layout_width="225dp"
android:layout_height="200dp"
android:background="#drawable/stopwatch2"
android:layout_marginTop="83dp"
android:layout_marginRight="3dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal|bottom">
<Chronometer
android:id="#+id/aChronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textColor="#ffffff"
android:layout_marginBottom="144dp"
android:layout_above="#+id/editText"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:text="#string/Explanation"
style="#style/Base.TextAppearance.AppCompat.Medium"
android:layout_above="#+id/button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="26dp"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:text="= 0"
android:layout_marginTop="8dp"
style="#style/Base.TextAppearance.AppCompat.Medium"
android:layout_alignTop="#+id/button"
android:layout_centerHorizontal="true"
android:layout_marginRight="-10dp"
android:textColor="#ffffff" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="50dp"
android:layout_height="40dp"
android:background="#drawable/cookie"
android:id="#+id/button"
android:layout_marginRight="-10dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/editText2"
android:layout_toStartOf="#+id/editText2"
android:layout_marginBottom="84dp" />
</RelativeLayout>
</FrameLayout>
If you run you particular layout in 5 different devices with different sizes, you will get 5 different results.
Well, this is because you have put specific values for layout_height, layout_width and the margins, like 225dp, 200dp. I know these are independent pixels, but when drawable is considered never set both width and height to a specific value. It messes up the aspect ratio. These settings will work well for one particular configuration of device, but not the rest. The device will pick different drawable based on the resolution of the device.
You need to try to design your relative to other views. Always make sure that the layout_width and layout_hight are in wrap_content. This will ensure that the drawable is loaded in correct aspect ration in all the devices and emulators.
I found a lot of question were asked on supporting different screen size where the screen size are varies from Tablet to phone and etc. I am writing my first android application and when I am looking at the layout in different phone, All of them are not relatively scalable to screen.
I am pasting a small RelativeLayout code here to understand how to make it proper scalable in less changes. I also followed the android official doc and learn two things
drawable images for different screen
use sp for mentioning text size and for rest of them use dp
But it's not helping me
Code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffd5d6d6">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:background="#ffffffff"
android:elevation="#dimen/abc_action_bar_default_height_material">
<ImageView
android:id="#+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:src="#drawable/ic_back" />
<TextView
android:id="#+id/profileDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Test"
android:textColor="#ff3c3f41"
android:textSize="15dp" />
<ImageView
android:id="#+id/flag"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:layout_alignWithParentIfMissing="false"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:src="#drawable/temp_ic_share" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="52dp">
<TextView
android:id="#+id/roommate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="Who are you?"
android:textColor="#ff3c3f41"
android:textSize="18dp" />
<Button
android:id="#+id/foodie"
style="#style/Widget.AppCompat.ButtonBar"
android:layout_width="60dp"
android:layout_height="38dp"
android:layout_alignParentStart="false"
android:layout_marginLeft="56dp"
android:layout_marginTop="80dp"
android:background="#fa6425"
android:text="Foodie"
android:textColor="#fff4f4f4"
android:textSize="12dp" />
<Button
android:id="#+id/button4"
style="#style/Widget.AppCompat.ButtonBar"
android:layout_width="80dp"
android:layout_height="38dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="80dp"
android:layout_toEndOf="#+id/foodie"
android:background="#fa6425"
android:text="Beach bum"
android:textColor="#fff4f4f4"
android:textSize="12dp" />
<Button
android:id="#+id/button5"
style="#style/Widget.AppCompat.ButtonBar"
android:layout_width="80dp"
android:layout_height="38dp"
android:layout_alignTop="#+id/button4"
android:layout_marginLeft="15dp"
android:layout_toEndOf="#+id/button4"
android:background="#fa6425"
android:text="Tree hugger"
android:textColor="#fff4f4f4"
android:textSize="12dp" />
</RelativeLayout>
<Button
android:id="#+id/button"
style="#style/Widget.AppCompat.ButtonBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#fa6425"
android:text="Send"
android:textColor="#fff4f4f4" />
</RelativeLayout>
As you can see that I am including two Parallel RelativeLayout in one main RelativeLayout. here the views on three different size:
nexus one
nexus 5
nexus 6
Best alignment is in Nexus 5 screen. Do I need to create different layout folder i.e. hdpi, mdpi and etc? If I am not wrong then I don't need to because my application is going to run only on phone devices (in portrait mode only).
How can I make scalable screen layouts. Any help would be appreciable :)
If you want to force all the views to have the same ration on screen the only way is to give it a size dynamically after you calculated the ratio between the desired pixels and the screen density, which is not really a solution, What you need to understand is when working with various screen sizes, each one suppose to behave differently, a Tablet screen is expected to be bigger and thus having more room for elements to show up on screen, a phone screen is smaller and less elements should be showed on screen, you need to adjust your view to support all of these screens and the proper way is to write a different layout for tablets and phones, or even different layout by screen dpi.
I am pretty new, I am using Android Studio, is that what you are using? First thing first, if you always want you activity to be in portrait mode, use this code in your manifest, you have to add the code to each activity you want to stay in portrait mode. If you don't, and you don't add code to handle the switch in screen orientation, the phone will likely crash.
<activity
android:name=".TitleActivity"
android:label="#string/title_activity"
android:screenOrientation="portrait" >
</activity>
Instead of a relative view, Try the Linear Layout.
You would have your Main Layout, with a few nested Linear Layouts.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/example">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Title Here"
android:id="#+id/Title"
android:layout_gravity="top|center_horizontal"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:layout_marginBottom="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="50dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button3"
android:layout_weight="1"
android:layout_marginRight="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_gravity="center_horizontal"
android:background="#drawable/test"
android:layout_margin="50dp" />
</LinearLayout>
This layout has A title Above the three buttons, Then three buttons, then an image view below, it scales from 3.7 to 7.0. Larger than 7, I would make another layout.
You need an image named test in your drawable file.
use this Library will help you to set a Responsive scalable Views for all the devices Layouts
https://github.com/intuit/sdp
irs really easy and simpl just replace.
android:layout_width="50dp"
android:layout_height="60dp"
with.
android:layout_width="50sdp"
android:layout_height="60sdp"
and for textView
android:textSize="60ssp"
instead of. sp
I am setting up images for different devices as per official google docs.As per google docs we should always use dp(density independent pixels) because pixels may varies for different devices.
So i have managed images as per dp(density independent pixels).
I have put images in drawable xhdpi,hdpi,mdpi and ldpi. it works well for most of devices but for different devices ppi pixels may varies from device to device so dp(density independent pixels) is not fixed so my all calculations according to dp(density independent pixels) goes wrong and cannot be set properly.
Let me explain me with example.
here is my xml i am setting up :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:orientation="horizontal" >
<ImageView
android:id="#+id/ft_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
<ImageView
android:id="#+id/ft_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
<ImageView
android:id="#+id/ft_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
<ImageView
android:id="#+id/ft_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
<ImageView
android:id="#+id/ft_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
<ImageView
android:id="#+id/ft_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/ico_test" />
</LinearLayout>
when i see this layout in Micromax canvas 4(294 ppi pixels) it seems perfect.
but in Google Nexus 4(318 ppi pixels) it leaves more space from right side(you can see it in images i have attached.).
i tried to get following details
density :
dpHeight :
dpWidth :
using below java code :
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics ();
display.getMetrics(outMetrics);
float density = getResources().getDisplayMetrics().density;
float dpHeight = outMetrics.heightPixels / density;
float dpWidth = outMetrics.widthPixels / density;
i get following results for nexus 4 and canvas 4 :
(canvas 4)
density : 2.0
dpHeight : 640
dpWidth : 360
(nexus 4)
density : 2.0
dpHeight : 592
dpWidth : 384
as you can see here dp(density independent pixels) varies for these devices
i think it is because of different ppi pixels so all my calculations according to dp(density independent pixels) goes wrong.
so how can i manage images if dp is not fixed.??
i have also attached screen shot of the images how layout looks in canvas 4 and nexus 4.
I have also referred this question How do I convert ppi into dpi for Android images?
i know i can adjust layouts using the layout weight but i think there must be another solution to this problem.
Please see and help me to solve the problem.
You just cannot support all the devices, Either you can create different layouts or different drawables to target each device.
The best thing you can do is make a flexible UI that divides the view in proportions and for doing this WEIGHT come into existence . Just use weight to divide the UI into proportion like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:orientation="horizontal"
android:weightSum="6">
<ImageView
android:layout_weight="1"
android:id="#+id/ft_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_weight="1"
android:id="#+id/ft_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_weight="1"
android:id="#+id/ft_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_weight="1"
android:id="#+id/ft_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_weight="1"
android:id="#+id/ft_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_weight="1"
android:id="#+id/ft_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/ic_launcher" />
</LinearLayout>
The dp pixels are density independent, not proportion independent. The difference in proportion of height to width between the two devices is the issue you are having, not an occurrence of non-standard dp. The only proper solution is to adjust the weight based on difference in proportion.
If density independent pixels were dependent on the pixels per inch, a density dependent unit, then they would also be density dependent.
Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:orientation="horizontal" >
<ImageView
android:id="#+id/ft_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/ft_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/ft_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/ft_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/ft_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/ft_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
I do in such a way
Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth()/6; //number of buttons
button.setLayoutParams(new LinearLayout.LayoutParams(screenWidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
button2.setLayoutParams(new LinearLayout.LayoutParams(screenWidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
....
make it as for each buttons in same way..
or
Tabbar concept works in anotherway..
For your problem as seen in your screenshot your background have repeatable texture. Crop the image for texture and use repeatable background in place of single image. You can use following XML for repeatable background bg_repeat.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background"
android:tileMode="repeat" />
background.png
give your cropped image as src here and put this XML file in your drawable. Now, in your layout do this -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_repeat"/>
</LinearLayout>
IMO this will serve your purpose and it will also save you some bites.
I think you need to work with weight here.Just put the same code in your XML and see the difference:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/ft_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/ft_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<ImageView
android:id="#+id/ft_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<ImageView
android:id="#+id/ft_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/ft_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ico_test" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/ft_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/ico_test" />
</LinearLayout>
You just cannot support all the devices, Either you can create different layouts or different drawables to target each device.
Instead of linear layout use Relative layout that will be better for all devices.
I am using some .png images for my Android app's UI. I have kept the images in the 'res/drawable' directory. I read in some tutorials that Android automatically scales up the images when the screen resolution is bigger than mdpi. But when I run my app on big screened devices, the images are displayed as their original sizes, and not scaled up. Rest of the space is empty( black). What am I doing wrong here? Below is the XML for my layout, if it helps:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:theme="#android:style/Theme.Black.NoTitleBar"
>
<ImageView
android:id="#+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1"
android:clickable="false"
android:contentDescription="#string/p"
android:src="#drawable/volbar" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:contentDescription="#string/p"
android:src="#drawable/head" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentRight="true"
android:layout_marginBottom="33dp"
android:layout_marginRight="19dp"
android:text="#string/press_to_update" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView2"
android:clickable="false"
android:contentDescription="#string/p"
android:src="#drawable/frag11"
/>
<ImageView
android:id="#+id/imageView4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView9"
android:layout_alignParentLeft="true"
android:clickable="false"
android:contentDescription="#string/p"
android:src="#drawable/base" />
</RelativeLayout>
I'm guessing that you want your image to scale up to fill the space. If that is the case, you will need to specify scaledType for your ImageView:
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="cropInside" />
Experiment with different values from ImageView.ScaleType to get the effect you want.
FYI, when you put an image in res/drawable, it is scaled according to device density. For instance, if your png is 200x150, it will be scaled to 300x225 on a device with 1.5 density. This scaling happens independent of the scaleType.
How can I enlarge my activity when it is running on bigger screen? I have tried android:scaleType="fitXY" for my imageview but it doesn't work. I have tried plenty of code i researched but none of them work. When I run it on Samsung galaxy S2, it work perfectly. But when I tried it on galaxy note or galaxy S2, the UI is totally different. All imageview are small.
Here's the UI for S2:
Here's the UI for note and S3:
Here's the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/imageDesc"
android:src="#drawable/welcome" />
<Button
android:id="#+id/btnFinance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="240dp"
android:background="#drawable/btn_finance" />
<Button
android:id="#+id/btnHowtouse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="305dp"
android:background="#drawable/btn_howto" />
<Button
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="370dp"
android:background="#drawable/btn_settings" />
<Button
android:id="#+id/btnAbout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="435dp"
android:background="#drawable/btn_about" />
</RelativeLayout>
You can make different images and layouts for each resolution.
Use folders for the different image resolution like drawable-hdpi and drawable-xhdpi
I suggest to read here for more details: Supporting Multiple Screens