Question

I have used dip(eg: width = 30dip, scroll bar till the middle of screen) , as parameter But in 3.5 inches phone it looks fine, in 5 inches screen phones its not at all coming till middle, here goes below middle. why?

xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="450dip"
        android:paddingLeft="10dip">

        <ImageView
            android:id="@+id/gdi_arrow_up"
            android:layout_width="27dip"
            android:layout_height="27dip"
            android:layout_marginLeft="10dip"
            android:scaleType="fitCenter"
            android:layout_marginBottom="-8dip"
            android:src="?attr/asListArrowUp"  />

         <include layout="@layout/main_menu"/>


        <ImageView
            android:id="@+id/gdi_arrow_down"
            android:layout_width="27dip"
            android:layout_height="27dip"
            android:scaleType="fitCenter"
            android:layout_marginBottom="-8dip"
            android:layout_below="@android:id/list"/>

    </RelativeLayout>
Was it helpful?

Solution

dip stands for density independent pixel, this means 2 screens with the same size but different density will treat that value the same, however 2 screens of different size (large vs normal) will treat the value differently.

your 5 inch phone may be reported as large and your 3.5 inch phone as normal causing the issue but I'm not sure.

also in your realative layout I'd recommend using match_parent for the height, you usually will not use set widths for viewGroups.

OTHER TIPS

Set the LayoutParameters of the RelativeLayout dynamically as screenWidth/2..it will work on all devices..

In your onCreate do something like this:-

RelativeLayout rel = (RelativeLayout) findViewById(R.id.rel1);
int screenHeight = getWindowManager()
                    .getDefaultDisplay().getHeight();
rel.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, screenHeight/2));

Hope this helps.

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