Question

How do I show controls at a fixed position for various screen resolutions in Android?

I have a screen design like below

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:gravity="center_horizontal"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical"
   android:background="@drawable/img_background_loadbackground">
<TableRow>
<TextView
   android:id="@+id/tv1"
   android:layout_width="fill_parent" 
   android:layout_height="300sp"/>
</TableRow>

<TableRow>
</TableRow>
<ProgressBar 
   android:id="@+id/progressbar" 
   style="?android:attr/progressBarStyleHorizontal" 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" />
</TableLayout>

It is working in HVGA(320x480) resolution, the progressbar appears at the bottom of the screen, but if I run in other resolution (WQVGA432 - 240x432) the progressbar appears in the middle of the screen. I am not able to show it in a fixed position.

I am using the manifest file show below but no output

<supports-screens android:smallScreens="true"  
                android:normalScreens="true" 
                android:largeScreens="true"  
                android:anyDensity="true" />

I don't have a solution so please give me some idea to resolve the issue.

Was it helpful?

Solution

If you want your layouts to work on different resolution screens your should be sizing them using dip as the unit. For example:

android:layout_marginRight="10dip"

dip stands for Device Independent Pixel and using these in your layout means that Android will automatically scale your layout depending on which display the device running your application has.

You can read about these in the Supporting Multiple Screens page in the Android Developer Documentation. This document also has some other options for handling different displays but I think using dip is probably the easiest.

OTHER TIPS

It depends on how you have defined your layout: posting your layout XML will help here.

I would guess if its in the middle you have something like:

android:layout_gravity="center"

But yeah, posting your XML would be a bit help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top