• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Facing problem - single layout that work for all tabs in any density

Hi All,

I am facing problem in running application with HIGH & LOW density with single layout(xml file). I have read so many threads and verified developers.android site too..

All mentioned to specify the size of the components should be in dp or wrap_content or fill_content, then android itself take care of the density use,since android is density independent.

And also to place the layouts in layout-nodpi folder for density free. Then in one of the thread, they mentioned to use
<supports-screens android:resizeable="true"
android:largeScreens="true" android:normalScreens="true"
android:anyDensity="true"></supports-screens>.

I also tried by placing the layouts in ldpi,mdpi,xhdpi and hdpi.But no use.

I have tried all the above,but i couldnt get the application UI same in two different density.. I am using "Funbook micromax"[Normal density] and "Intex iBuddy"[Low density] model, both are 7 Inch.

Kindly help me to use single layout to be work in all type of density and screen size..
 
Supporting multiple screen sizes is always a challenge. You want to provide the best experience and use all screen real estate for each device but at the same time keep the application consistent.

In your case you have one layout file (I am guessing in res/layout) but you're having trouble with getting a consistent result between multiple devices? I bet I can help but could you please post your layout code and even screenshots would help. Layout xml files can be tricky and one line could make or break how your layout works.

Hope I can help.
 
Hi...

The following is one of the layout in our application... As you said, we will try with this as sample, if we achieve the criteria.. Will try the same in remaining screens..

The layout is inflated to create some more rows dynamically...

<?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:layout_marginTop="20.0dip"
android:orientation="vertical" >

<TableRow
android:id="@+id/Row1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20.0dip"
android:weightSum="1" >

<TextView
android:id="@+id/Row1_TV1"
android:layout_weight="0.225"
android:gravity="center"
android:text="Row1_Value1"
android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
android:id="@+id/Row1_TV2"
android:layout_weight="0.225"
android:gravity="center"
android:text="Row1_Value2"
android:textAppearance="?android:attr/textAppearanceSmall" />

<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.325" />

<TextView
android:id="@+id/Row1_TV3"
android:layout_weight="0.225"
android:gravity="center"
android:text="Row1_Value3"
android:textAppearance="?android:attr/textAppearanceSmall" />
</TableRow>

<TableRow
android:id="@+id/Row2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/Row1"
android:layout_marginTop="6dip"
android:orientation="horizontal"
android:weightSum="1" >

<TextView
android:id="@+id/Row2_TV1"
android:layout_weight="0.225"
android:gravity="center"
android:text="Row2_Value1"
android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
android:id="@+id/Row2_TV2"
android:layout_weight="0.225"
android:gravity="center"
android:text="Row2_Value2"
android:textAppearance="?android:attr/textAppearanceSmall" />

<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.325" />

<TextView
android:id="@+id/Row2_TV3"
android:layout_weight="0.225"
android:gravity="center"
android:text="Row2_Value3"
android:textAppearance="?android:attr/textAppearanceSmall" />
<!-- /> -->

</TableRow>

</RelativeLayout>

Thanks In Advance... Also I am grateful to you for your reply..
 
Your layout seems fine to me. I tested your exact code and here is the results

Phone
Image%202013.08.21%2010%3A05%3A35%20AM.png

Tablet
Image%202013.08.21%2010%3A05%3A50%20AM.png

Is this not what you were expecting or do you not get these results?
 
Yes, I dont want this output... Actually What I need is, the size of the Components and appearance like text size,image size, size of components should be same in all density and screen size of TABLETS...

Onemore thing, we are trying this only for TABLET. Not for other resource like mobile or PC.

I have seen the result as we expected in one sample application, which is downloaded from Google play store. I have seen the resource files of the application, how it performs perfect as independent to density and screensize.. But I couldnt find out..

So, I know the result what I expect is possible. But dont know the way to acheive.


Kindly help me..
 
I have seen the result as we expected in one sample application, which is downloaded from Google play store.

Can you provide a link so I can test this sample application?

Try to set the TextView size to something in sp. Here is the difference between dp and sp:

dp
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".

sp
Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.
 
SP is more used for text size.. stick to dp or dip for objects.

Backing up to your original question, I think what you want to do is have multiple layout files.. read this page: Supporting Different Screen Sizes | Android Developers

If you only provide one layout the device will use it and if you provide multiple it will use the layout that is best for its size (determined by folder).

The sample app you linked to is very odd. For one everything is super small on my HTC One. Looking at its package contents it seems it uses adobe air cross platform stuff...so its not a very good app to go off of for compare.

Let me know if you understand more after reading that link above.
 
Back
Top Bottom