Unable to fit this layout to multiple screen resolution in android
i have a Relative layout which has some buttons and imagebuttons with tabbar in bottom.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/statustext" android:layout_width="wrap_content" android:textColor = "@color/white" android:layout_height="wrap_content"
android:text="Welcome to www.****.com" android:layout_weight = "1" />
<EditText android:id="@+id/welcome" android:hint="Please enter your name" android:layout_width="fill_parent" android:scaleType="center" android:singleLine="true"
android:layout_below = @+id/statustext" android:cursorVisible = "false" android:layout_height="wrap_content" android:layout_weight = "1" >
</EditText>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height= "wrap_content"
android:orientation="vertical" android:layout_below = "@+id/welcome">
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button1" android:text="new user" android:layout_below="@+id/welcome" android:layout_width="103dp" android:layout_alignLeft="@+id/welcome"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button4" android:text="Registered?" android:layout_below="@+id/button1" android:layout_width="103dp" android:layout_alignLeft="@+id/button1" android:layout_alignRight="@+id/button1"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button7" android:text="Forgot Pass" android:layout_below="@+id/button4" android:layout_width="103dp" android:layout_alignLeft="@+id/button4" android:layout_alignRight="@+id/button4"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button10" android:text="Email" android:layout_below="@+id/button7" android:layout_width="103dp" android:layout_alignLeft="@+id/button7" android:layout_alignRight="@+id/button7"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button2" android:text="Sign-In" android:layout_width="103dp" android:layout_toRightOf="@+id/button1" android:layout_alignTop="@+id/button1" android:layout_alignBottom="@+id/button1"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button5" android:text="Username" android:layout_below="@+id/button2" android:layout_width="103dp" android:layout_alignLeft="@+id/button2" android:layout_alignRight="@+id/button2"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button8" android:text="Password" android:layout_below="@+id/button5" android:layout_width="103dp" android:layout_alignLeft="@+id/button5" android:layout_alignRight="@+id/button5"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button11" android:text="Cart" android:layout_below="@+id/button8" android:layout_width="103dp" android:layout_alignLeft="@+id/button8" android:layout_alignRight="@+id/button8"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button3" android:text="Search" android:layout_width="103dp" android:layout_toRightOf="@+id/button2" android:layout_alignTop="@+id/button2" android:layout_alignBottom="@+id/button2"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button6" android:text="Call *****" android:layout_below="@+id/button3" android:layout_width="103dp" android:layout_alignLeft="@+id/button3" android:layout_alignRight="@+id/button3"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button9" android:text="Register" android:layout_below="@+id/button6" android:layout_width="103dp" android:layout_alignLeft="@+id/button6" android:layout_alignRight="@+id/button6"></Button>
<Button android:layout_height="wrap_content" android:layout_weight = "1" android:id="@+id/button12" android:text="Follow Us" android:layout_below="@+id/button9" android:layout_width="103dp" android:layout_alignLeft="@+id/button9" android:layout_alignRight="@+id/button9"></Button>
<Button android:id="@+id/bluebutton" android:layout_below = "@id/button10" android:layout_weight = "1" android:layout_height="wrap_content" android:layout_width="103dp" android:layout_alignParentLeft = "true" android:background="@drawable/blue_logo"></Button>
<Button android:id="@+id/bluebutton" android:layout_below = "@id/button11" android:layout_weight = "1" android:layout_height="wrap_content" android:layout_width="103dp" android:layout_toRightOf = "@+id/dialer" android:background="@drawable/orange_logo"></Button>
<Button android:id="@+id/blackbutton" android:lay开发者_高级运维out_below = "@id/button12" android:layout_weight = "1" android:layout_height="wrap_content" android:layout_width="103dp" android:layout_toRightOf="@+id/orangebutton" android:background="@drawable/black_logo" ></Button>
</RelativeLayout>
</RelativeLayout>
My problem is that i looks fine in Google Nexus(H-533 ,W-320) calculated by
Display display = getWindowManager().getDefaultDisplay();
int screenHeight = display.getHeight();
int screenWidth = display.getWidth();
Log.i("Screen Height = ",Integer.toString(screenHeight) );
Log.i("Screen Width = ",Integer.toString(screenWidth) );
and i have created different folders according to resolution,its taking xml from
layout-normal-mdpi
when i see this layout in HTC legend(H - 480 W-320) Or Samsung Ace the last three image buttons looking compressed about half of their height between normal button and Tabbar.The problem i guess in the small height with respect to Nexus, and all three devices are using same mdpi resolution xml file .So what should i do to make this layout work according to diff screen heights of same mdpi resolution devices.
If thats not possible from layout
weight
can i change button size programmatically after calculating screen size?
Thanks
Hey check this revised version and if problem persist comment me
enter code here`<?xml version="1.0" encoding="UTF-8"?>
<TextView android:id="@+id/statustext" android:layout_width="wrap_content"
android:textColor="@color/white" android:layout_height="wrap_content"
android:text="Welcome to www.****.com" android:layout_weight="1" />
<EditText android:id="@+id/welcome" android:hint="Please enter your name"
android:layout_width="fill_parent" android:scaleType="center"
android:singleLine="true" android:layout_below="@+id/statustext"
android:cursorVisible="false" android:layout_height="wrap_content"
android:layout_weight="1">
</EditText>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_below="@+id/welcome">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/linlayout1">
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button1" android:text="new user"
android:layout_width="fill_parent"
></Button>
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button2" android:text="Sign-In"
android:layout_width="fill_parent"
></Button>
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button3" android:text="Search"
android:layout_width="fill_parent"
></Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_below="@+id/linlayout1" android:layout_height="wrap_content"
android:id="@+id/linlayout2">
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button4" android:text="Registered?"
android:layout_width="fill_parent"
></Button>
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button5" android:text="Username"
android:layout_width="fill_parent"
></Button>
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button6" android:text="Call *****"
android:layout_width="fill_parent"
></Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_below="@+id/linlayout2" android:layout_height="wrap_content"
android:id="@+id/linlayout3">
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button7" android:text="Forgot Pass"
android:layout_width="fill_parent"
></Button>
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button8" android:text="Password"
android:layout_width="fill_parent"
></Button>
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button9" android:text="Register"
android:layout_width="fill_parent"
></Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_below="@+id/linlayout3" android:layout_height="wrap_content"
android:id="@+id/linlayout4">
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button10" android:text="Email"
android:layout_width="fill_parent"
></Button>
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button11" android:text="Cart"
android:layout_width="fill_parent"
></Button>
<Button android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/button12" android:text="Follow Us"
android:layout_width="fill_parent"
></Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_below="@+id/linlayout4" android:layout_height="wrap_content"
android:id="@+id/linlayout5">
<Button android:id="@+id/bluebutton" android:layout_below="@id/button10"
android:layout_weight="1" android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@drawable/blue_logo"></Button>
<Button android:id="@+id/bluebutton" android:layout_below="@id/button11"
android:layout_weight="1" android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@drawable/orange_logo"></Button>
<Button android:id="@+id/blackbutton" android:layout_below="@id/button12"
android:layout_weight="1" android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@drawable/black_logo"></Button>
</LinearLayout>
</RelativeLayout>
`
and yes please dont forget to write in your manifest file under application tag ending
</application>
<supports-screens android:smallScreens="true"
android:normalScreens="true" android:largeScreens="true"
android:anyDensity="true">
</supports-screens>
'
this will do your full work
thanks and enjoy happy coding
精彩评论