Jenda
Jenda

Reputation: 61

Android XML different margin on long screen

Is there a way how to set a different margin for a XML view on long screens?

As soon as screen ratios are quite diverse, i need to set a top margin for a view only for long screens, such as Samsung Note II (1280x720) to display my XML properly. Every opinion appreciated.

Upvotes: 0

Views: 2282

Answers (4)

1999493
1999493

Reputation: 96

I think you have to work with relative layout with And put your Images in drawable .so that your Image well Managed By itself. I have done that something like this:-

<?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/logosmall"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="180dp"
        android:layout_height="80dp" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/logo2" />
    </LinearLayout>
</RelativeLayout>

Upvotes: 0

RobinHood
RobinHood

Reputation: 10969

Create separate folder named layout-xhdpi inside resource and define your appropriate xml with margin there, hope it works for you!

Upvotes: 0

Kaidul
Kaidul

Reputation: 15875

You should use different folder name for different layout. Like:

res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

Read here for details

Upvotes: 1

Jaldip Katre
Jaldip Katre

Reputation: 3406

You will need to create 4 different layouts to support multiple screen sizes.. Refer Android Multiple screen support

Using this you can set margin in larger layout

Upvotes: 0

Related Questions