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

Apps DP (understanding?) Issue

Hi,

I'm not sure if I'm doing something wrong or I've misunderstood how density-independent pixels work.

I'm trying to build a layout that scales in proportion for any screen size, but as you can see in the screenshots below, the text and the other parts I've defined in DP don't scale properly on larger screens.

My layout XML is:

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
	android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">

	<TextView 
		android:background="#F995D0" 
		android:id="@+id/TextView01" 
		android:layout_width="fill_parent" 
		android:textColor="#FFFFFF" 
		android:typeface="sans" 
		android:layout_gravity="center_horizontal" 
		android:gravity="bottom|right" 
		android:paddingRight="5dp" 
		android:layout_height="100dp" 
		android:textStyle="bold" 
		android:textSize="32dp" 
		android:text="text1" />

	<LinearLayout 
		android:orientation="vertical"
		android:background="#FFFFFF"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent" 
    	android:paddingBottom="40dp" 
    	android:paddingTop="30dp"
    	xmlns:android="http://schemas.android.com/apk/res/android" >
    
    	<TextView 
    		android:layout_weight="1" 
    		android:id="@+id/TextView02" 
    		android:textColor="#FFFFFF" 
    		android:typeface="sans" 
    		android:gravity="left|center_vertical" 
    		android:paddingLeft="15dp" 
    		android:background="@drawable/rounded_edges" 
    		android:layout_width="250dp" 
    		android:layout_gravity="right" 
    		android:textStyle="bold" 
    		android:textSize="25dp" 
    		android:layout_marginRight="-10dp" 
    		android:layout_height="fill_parent" 
    		android:layout_marginTop="10dp" 
    		android:text="text2" />
    	
    	<TextView android:layout_weight="1" android:id="@+id/TextView01" android:textColor="#FFFFFF" android:typeface="sans" android:gravity="left|center_vertical" android:background="@drawable/rounded_edges" android:layout_width="250dp" android:layout_gravity="right" android:textStyle="bold" android:layout_marginRight="-10dp" android:paddingLeft="15dp" android:layout_height="fill_parent" android:layout_marginTop="10dp" android:textSize="25dp" android:text="text3"></TextView>
    	<TextView android:layout_weight="1" android:layout_marginRight="-10dp" android:textColor="#FFFFFF" android:background="@drawable/rounded_edges" android:paddingLeft="15px" android:textStyle="bold" android:layout_width="250dp" android:typeface="sans" android:gravity="left|center_vertical" android:layout_gravity="right" android:id="@+id/TextView03" android:textSize="25dp" android:layout_height="fill_parent" android:layout_marginTop="10dp" android:text="text4"></TextView>

	</LinearLayout>

</LinearLayout>


14t1lrk.png


2mfkvug.png
 
You have a lot going on -- I might suggest you look into RelativeLayout

At a glance though I'd say you're having issues not with DP, but with using layout_weight and fill_parent at the same time.

Try setting your layout_height to 0dp and keeping the layout_weight the same. layout_weight is meant to fill the space dynamically between the objects so you dont need to set a height (or width if your orientation is horizontal).
 
Back
Top Bottom