tags:

views:

98

answers:

1

Hai Friends, I have developed an application which en-composes list views and posted that .apk file in my htc device, the design and alignment everything works fine,but the problem When i am testing in various devices such as Morotolo Droid,Nexus Devices the alignment of Listviews goes wrong, so i planned to use the Layout folder as layout-hdpi,layout-ldpi, and layout-mdpi, for that i changed my manifest file as

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

Is it right putting android:anyDensity="true",also i used dp instead of dip. I went through this url, but still am not able to get a clear idea in this http://developer.android.com/guide/practices/screens_support.html. so friends pls tell me(help me) to get clear idea in this and tell what mistakes i have doing. This is my main page xml code frnds.

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/background_retinav2">   

     <LinearLayout android:layout_gravity="center" android:foregroundGravity="bottom" android:background="@color/white" android:id="@+id/rl_1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
        <ImageView  android:paddingTop="3dp" android:id="@+id/starthideimage" android:layout_width="30dp" android:layout_height="35dp" android:src="@drawable/newback" />
        <HorizontalScrollView  android:paddingTop="8dp" android:id="@+id/gv"
        android:layout_width="wrap_content" android:layout_marginTop="0dp"
        android:layout_height="wrap_content" android:background="#ffffff"
        android:scrollbars="none" android:layout_weight="1" android:foregroundGravity="bottom">
        <LinearLayout android:id="@+id/san_tag" android:layout_width="wrap_content" android:layout_height="wrap_content">
        </LinearLayout>
    </HorizontalScrollView>
    <ImageView  android:paddingTop="3dp" android:id="@+id/Endhideimage" android:layout_width="30dp" android:layout_height="35dp" android:src="@drawable/newforward" />
    </LinearLayout>

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:id="@android:id/tabcontent"  
        android:layout_width="fill_parent"  android:layout_height="fill_parent">



         <ListView android:id="@+id/content_movies" android:cacheColorHint="@color/cachecolor" 
           android:layout_weight="1" android:scrollbars="vertical"
           android:layout_width="fill_parent" android:layout_height="420dp"/>

        </FrameLayout>   
 </LinearLayout>

<TabWidget
    android:id="@android:id/tabs"
    android:gravity="bottom"
    android:layout_gravity="bottom"
    android:listSelector="@color/gray"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" /> 

</TabHost>
A: 

you should get width and height of device on run time

Display display = getWindowManager().getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight();

and the make your layout accordingly

if you can code your layout programatically instead of using xml

it,d be best practice

sajjoo
That is not the best practice for Android. If at all possible, you should design your layout in XML, to keep the code separate from the layout. Naturally in some instances you will have to make layout changes at runtime, but in most cases XML is the preferred way to set your layout.
kcoppock
so you trying to say that for different devices we should make plenty of XML files?. why not just make one method for the layout and change it on run time. for dynamic work you have to work without XML.
sajjoo