[英]Android Multiple Screen Support for tablet
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="450dp"
android:background="#f8f9fe" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/extremelysorry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp"
android:background="@drawable/pressicon"
android:orientation="vertical" >
<TextView
android:id="@+id/extremelysorry1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:padding="5dip"
android:text=" "We are extremely sorry, request your valuable ."
android:textColor="#FFFFFF"
android:textSize="20dip"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_name"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/pressicon"
android:orientation="vertical" >
<TextView
android:id="@+id/signetno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:padding="5dip"
android:text=" Please enter your Loyalty Card No/Name,Mobile No/Name "
android:textColor="#FFFFFF"
android:textSize="20dip"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:orientation="vertical" android:layout_marginTop="30dp">
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<LinearLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/labelbg" >
<TextView
android:id="@+id/loyaltyLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:padding="5dp"
android:text="Membership Card No."
android:textColor="#FFFFFF"
android:textSize="20dp" />
</LinearLayout>
<EditText
android:id="@+id/ed_cardno"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:background="@drawable/textbox_n"
android:ems="10"
android:hint="Touch here to enter"
android:imeOptions="actionDone|flagNoExtractUi"
android:inputType="number"
android:paddingLeft="5dp"
android:singleLine="true"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp" >
<LinearLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/labelbg" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:padding="5dp"
android:text="Name"
android:textColor="#FFFFFF"
android:textSize="20dp" />
</LinearLayout>
<EditText
android:id="@+id/ed_name"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:autoText="true"
android:background="@drawable/textbox_n"
android:ems="10"
android:hint="Touch here to enter"
android:imeOptions="actionDone|flagNoExtractUi"
android:paddingLeft="5dp"
android:singleLine="true"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_emailid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp" >
<LinearLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/labelbg" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:padding="5dp"
android:text="Mobile No"
android:textColor="#FFFFFF"
android:textSize="20dp" />
</LinearLayout>
<EditText
android:id="@+id/ed_mobileno"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:background="@drawable/textbox_n"
android:ems="10"
android:hint="10digit Mobile number"
android:imeOptions="actionDone|flagNoExtractUi"
android:numeric="integer"
android:paddingLeft="5dp"
android:phoneNumber="true"
android:singleLine="true"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_cardno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp" >
<LinearLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/labelbg" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:padding="5dp"
android:text="Email ID"
android:textColor="#FFFFFF"
android:textSize="20dp" />
</LinearLayout>
<EditText
android:id="@+id/ed_emailid"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:background="@drawable/textbox_n"
android:ems="10"
android:hint="Touch here to enter"
android:imeOptions="actionDone|flagNoExtractUi"
android:inputType="textEmailAddress"
android:paddingLeft="5dp"
android:singleLine="true"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_comeagain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp" >
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/back"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:focusable="true"
android:background="@drawable/back_button"
android:textColor="#ff29549f" />
<Button
android:id="@+id/comment_next"
android:layout_width="wrap_content"
android:layout_height="37dp"
android:layout_marginLeft="420dp"
android:background="@drawable/next_button"
android:focusable="true"
android:textColor="#ff29549f" />
<Chronometer
android:id="@+id/start_quiz_time1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.19"
android:textSize="15sp"
android:visibility="invisible" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp"
android:background="@drawable/pressicon"
android:orientation="vertical" >
<TextView
android:id="@+id/manadatory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:padding="5dip"
android:text=" *Mandatory: The information is confidential & will not"
android:textColor="#FFFFFF"
android:textSize="20dip" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
This is my code, but it does not support multiple screen. 这是我的代码,但它不支持多个屏幕。 Widgets get displaced. 小部件流离失所。
How to change this code as if I run this on any tablet, it'll looks the same on every tablet with different screen sizes and density? 如何更改此代码,就像我在任何平板电脑上运行它一样,它在每个具有不同屏幕尺寸和密度的平板电脑上看起来都一样?
It's because you are setting the size in dp for the layout height and width. 这是因为您在dp中为布局高度和宽度设置了大小。
You need look more about weight, with that your layout will adjust in the screen size. 您需要更多地了解重量,您的布局将根据屏幕尺寸进行调整。
Write Below Code into your Androidmanifest.xml file 将以下代码写入Androidmanifest.xml文件
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
And see below link for more information. 有关更多信息,请参阅以下链接。
There are two important parameters which needs to taken cared when you are designing an app which 在设计应用程序时,需要注意两个重要参数
should run on multiple devices: 应该在多个设备上运行:
Size: Size of a device in android is not defined as a unique physical value but as a range. 大小:android中设备的大小未定义为唯一的物理值,而是作为范围。
These are: small, normal, large and xlarge. 这些是:小,正常,大和xlarge。
Density: Density is also defined as a range. 密度:密度也定义为范围。
These are: ldpi, mdpi, hdpi and xhdpi. 它们是:ldpi,mdpi,hdpi和xhdpi。
For handling size you need to use have multiple layouts, one for each category of the size and you need to use different dp value for the height and width of the views for each of the layout as the sizeof a small and a large device will not be same. 对于处理大小,您需要使用多个布局,每个类型对应一个大小,并且您需要为每个布局使用不同的dp值作为视图的高度和宽度,因为小型和大型设备的大小不会一样的
For handling density you need to using different drawables for different screen densities ie you need to place different density drawables in different drawable folders. 为了处理密度,您需要针对不同的屏幕密度使用不同的drawable,即您需要在不同的可绘制文件夹中放置不同的密度drawable。
Eg: 例如:
These are the resolutions for a particular drawable 这些是特定drawable的决议
The ratio for this variation of the resolution is 3:4:6:8(ldpi:mdpi:hdpi:xhdpi) 此分辨率变化的比例为3:4:6:8(ldpi:mdpi:hdpi:xhdpi)
For further reading you can refer to this android developer's link: 有关进一步阅读,请参阅此Android开发人员的链接:
http://developer.android.com/guide/practices/screens_support.html http://developer.android.com/guide/practices/screens_support.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.