Reputation: 1101
I am new to android development. I am making a UI for my android app. Now, mdpi screen's height is 480px. So I designed my UI to have a height of 480px on mdpi's screens. But because the status bar takes some space at the top of the devices, some of my ImageViews in RelativeLayout are overlapping. How to compensate for the space the status bar takes? Because for different screens, the status bar will be of different sizes and in tablets the status bar might not even be at the top. I am confused, help!
EDIT: The XML :
<?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: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:scaleType="center"
android:src="@drawable/volbar" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:clickable="false"
android:contentDescription="@string/p"
android:scaleType="center"
android:src="@drawable/base" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:contentDescription="@string/p"
android:scaleType="center"
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:scaleType="center"
android:src="@drawable/frag1"
/>
</RelativeLayout>
Upvotes: 1
Views: 1015
Reputation: 1505
As other users suggested, you should not hard code the specific heights but use wrap_content
or match_parent
.
If you still want to follow this way, why don't you reduce the height of your RelativeLayout by the dimension of the ActionBar? In Android 4.0+ the default height is 48dip
, in landscape is 40dp
, in sw600dp is 56dp
. You can also get height programmatically calling getActionBar().getHeight()
in your activity. For more infos about ActionBar appearance, see this link.
Upvotes: 0
Reputation: 1623
In Relativelayout , you have used match_parent / wrap_content. So it will fit to the screen. But you have specified that you have designed the ui for 480px on mdpi's screens. Since it is not clear how you designed the ui to 480px on mdpi screen. I guess , might have used drawables used in Image View which fits the 480 px for mdpi screens. drawables should be placed in the ratio of 3:4:6:8
for example
lpdi:mdpi:hdpi:xhdpi = 3:4:6:8
for example if you keep an image for mdpi as 40px Then,for ldpi = 30 px , hdpi = 60px , xhdpi = 80px.
Upvotes: 2
Reputation: 4142
Don't try to set the height to a specific size. Use "wrap_content" or "match_parent" as the value for "layout_height" whenever possible.
If you feel like the content will be taller than the available screen height you will want to use a ScrollView as the container for the content.
If you feel like the content will always fit in the available screen height then you can simply use a container (like a RelativeLayout) with layout_height="match_parent".
If you have a specific layout you need help with you could post the XML.
Upvotes: 0
Reputation: 199975
Per the Supporting Multiple Screens Best Practices, you should design your layouts to expand or contract to fill the space available. On a phone, the most important part is making sure your content fits horizontally and (if needed) scrolls vertically. You can add a ScrollView if you need to fit more vertical content in a layout than your device has room.
Upvotes: 0