Reputation: 81
I am having a problem while making an app. Here's my xml Layout which is working fine on small screen but not working proper on Tabs.How How can I adjust the layout to make common for all screens. Also I would like to know that I have set textbox height in dps,w.r.t small screen(default one),but it is not occuping proper space in tab.So I can adjust it?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:weightSum="1"
android:background="#ffffffff">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.55"
android:weightSum="1"
android:background="#1E90FF">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/imageView"
android:background="@drawable/lock"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/textView11"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:textColor="#ffffffff"
android:textSize="20dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton8"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/f_icon"
android:layout_below="@+id/textView11"
android:layout_marginTop="60dp" />
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.45">
<EditText
android:layout_width="240dp"
android:layout_height="40dp"
android:id="@+id/editText10"
android:background="@drawable/edittextstyle"
android:drawableLeft="@drawable/textboxuser"
android:drawablePadding="2dp"
android:paddingLeft="5dip"
android:paddingRight="26dip"
android:hint="Username"
android:singleLine="true"
android:layout_gravity="center_horizontal"
android:textColor="#ff464646"
android:textSize="20dp"
android:layout_marginTop="20dp" />
<EditText
android:layout_width="240dp"
android:layout_height="40dp"
android:inputType="textPassword"
android:ems="10"
android:paddingLeft="10dip"
android:paddingRight="26dip"
android:background="@drawable/edittextstyle"
android:drawableLeft="@drawable/textboxpwd"
android:layout_margin="10dp"
android:id="@+id/editText11"
android:layout_gravity="center_horizontal"
android:hint="Password"
android:textSize="20dp" />
<Button
android:layout_width="240dp"
android:layout_height="40dp"
android:text="Sign In"
android:background="#1E90FF"
android:layout_margin="10dp"
android:id="@+id/button4"
android:layout_gravity="center_horizontal"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:text="Forgot Password !! Click Here"
android:id="@+id/textView10"
android:textColor="#ff424242"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:layout_marginBottom="68dp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Not a member yet? Join Now"
android:onClick="register"
android:id="@+id/button5"
android:textColor="#fffcfffa"
android:clickable="true"
android:background="#ff000000" />
</LinearLayout>
</LinearLayout>
Upvotes: 0
Views: 60
Reputation: 2186
Android also supports multiple versions of res/values based on size, screen orientation and many other configuration qualifiers:
res/values/dimens.xml
res/values-large/dimens.xml
res/values-xlarge/dimens.xml
res/values-xlarge-land/dimens.xml
In every dimens.xml you can put dimensions to use later in layouts
example view:
<EditText
android:layout_width="@dimen/edit_text_width"
android:layout_height="@dimen/edit_text_height" />
values/dimens.xml:
<resources>
<dimen name="edit_text_width">120dp</dimen>
<dimen name="edit_text_height">200dp</dimen>
</resources>
values/dimens-large.xml:
<resources>
<dimen name="edit_text_width">240dp</dimen>
<dimen name="edit_text_height">300dp</dimen>
</resources>
It is often all you need to support many screen sizes, so it's worth checking
Upvotes: 0
Reputation: 3904
If you can design intelligently to somehow look your layout more or less okey on all screen sizes then its ok. But normally you should create different layouts for different screen sizes like
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra-large screen size
res/layout-xlarge-land/my_layout.xml
For tablet you can declare separate layout like
res/layout/main_activity.xml # For handsets
res/layout-sw600dp/main_activity.xml # For tablets
But above all go through android developers website. Read all details. You will get all the info in more structural way
https://developer.android.com/guide/practices/screens_support.html
EDIT:
The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. For example, layouts for an extra-large screen should go in layout-xlarge/. Beginning with Android 3.2 (API level 13), the above size groups are deprecated and you should instead use the swdp configuration qualifier to define the smallest available width required by your layout resources.
res/layout-sw600dp/main_activity.xml # For tablets
Upvotes: 1