Skip to content Skip to sidebar Skip to footer

How Can I Resize The Layout And Scrollview According To Screen Resolution

I set the layout and scroll view for the screen resolution 480x800. How can I be compatible with other screen resolution? Here is my code. Please help me.

Solution 1:

First of all, Android does not support the concept of "screen resolution." There's screen size and screen (or pixel) density. Since you're already using density-independent pixels (dp), I imagine that your question is about supporting different screen sizes.

The way to support other screen sizes is to have size-specific resource directories. For instance, in addition to res/layout (where you probably now have the above layout file), you could have res/layout-large to support large screens. The details about this are described in the Guide topic Supporting Multiple Screens and the pages that it links to.

You might also consider not specifying an exact size for your views, but rather let them fill the parent or wrap their content. If that doesn't work for your layout and you need to specify view sizes, you can make the size a variable and define the size in the res/values, res/values-large, etc. folders. For instance, in res/layout/main.xml you could have your layout:

<RelativeLayoutandroid:layout_width="fill_parent"android:layout_height="@dimen/relative_layout_height"android:orientation="vertical" ><ScrollViewandroid:id="@+id/ScrollView01"android:layout_width="fill_parent"android:layout_height="@dimen/scroll_view_height"android:background="#86C3C6" ><TextViewandroid:id="@+id/tvHistory"android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="#86C3C6"android:gravity="right"android:focusable="true"android:text=""android:textColor="#FFFFFF" /></ScrollView></RelativeLayout>

Then in each values folder you can have a dimens.xml file with the relevant dimensions given appropriate values. In res/values/dimens.xml (for medium-size screens):

<dimenname="relative_layout_height">150dp</dimen><dimenname="scroll_view_height">200dp</dimen>

While in res/values-large/dimens.xml you would have:

<dimenname="relative_layout_height">250dp</dimen><dimenname="scroll_view_height">300dp</dimen>

That way, you would only need one layout and it would be parameterized by dimension values that would vary by screen size.

Solution 2:

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"//would fill what ever size it wud be.
android:orientation="vertical" >
  <ScrollView android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"//would fill what ever size it wud be.
    android:background="#86C3C6" >

Post a Comment for "How Can I Resize The Layout And Scrollview According To Screen Resolution"