简体   繁体   English

如何修复多个屏幕大小的应用程序

[英]how to fix application for multiple screen size

i have created an application in 2.2 version, if i run it in normal phone it works fine. 我已经在2.2版本中创建了一个应用程序,如果我在普通手机中运行它可以正常工作。 but in tablet still it works fine but the label, textveiw and other things remain in the same size of the mobile phone. 但在平板电脑中仍然可以正常工作,但标签,textveiw和其他东西仍然与手机大小相同。

I have used this code but its is not working. 我已经使用过这段代码,但它无效。

<supports-screens 
android:largeScreens="true" 
android:normalScreens="true" 
android:smallScreens="true" 
android:anyDensity="true" /> 

Is their any other wayto do so, that my application look good in tablet tooo. 是他们的任何其他方式,我的应用程序看起来在平板电脑太好了。

my xml code, and i am using it inside table layout 我的xml代码,我在表格布局中使用它

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:id="@+id/mainlayout"
    android:background="#ffffff" android:fadingEdge="horizontal|vertical" 
  >
    <RelativeLayout android:id="@+id/header_login"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView  android:id="@+id/login_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:paddingBottom="5px"
            android:paddingLeft="3px"
            android:paddingTop="5px"
            android:src="@drawable/sap_new" />
    </RelativeLayout>

 <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
         android:paddingTop="5dip"
            android:src="@drawable/login1" >
        </ImageView>
    <TableRow android:gravity="center" android:paddingTop="15px" android:layout_width="fill_parent">
         <TextView android:text="Username " android:layout_column="0" android:textColor="#000000" android:id="@+id/usrLbl"
            android:layout_width="wrap_content" android:gravity="right" />
        <TextView android:text="" android:layout_column="1"
            android:gravity="left" android:width="20dip" android:textColor="#FF0000" /> 
        <EditText android:id="@+id/sapuser" android:hint="Required"
            android:layout_column="2" android:width="150dip" android:paddingLeft="5dip"
             android:layout_marginRight="15dip" android:text="" android:singleLine="true" />
    </TableRow>
    <TableRow android:gravity="center"  android:layout_width="fill_parent">

        <TextView android:text="Password " android:layout_column="0" android:textColor="#000000"
             android:gravity="right" android:id="@+id/passLbl" />
        <TextView android:text="" android:layout_column="1"
            android:gravity="left" android:textColor="#FF0000" /> 
        <EditText android:id="@+id/password" android:hint="Required"
            android:paddingLeft="5dip" android:layout_column="2"
             android:password="true" android:text=""
            android:singleLine="true" android:layout_marginRight="15dip"   />
    </TableRow>

    <TableRow android:gravity="center"  android:layout_width="fill_parent">
    <TextView android:text="" android:layout_column="0"
             android:gravity="right"  />
        <TextView android:text="" android:layout_column="1"
            android:gravity="left" android:textColor="#FF0000" /> 
    <CheckBox
          android:id="@+id/ShowPassword"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="15dp"
          android:text="Show Password" android:textColor="#000000" android:background="@drawable/checkbox_background" android:button="@drawable/checkbox" /> 
    </TableRow>
    <TableRow android:gravity="center"  android:layout_width="fill_parent">
    <TextView android:text="" android:layout_column="0"
             android:gravity="right"  />
        <TextView android:text="" android:layout_column="1"
            android:gravity="left" android:textColor="#FF0000" /> 
    <CheckBox
          android:id="@+id/SavePassword"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="15dp"
          android:text="Save Password" android:textColor="#000000" android:background="@drawable/checkbox_background" android:button="@drawable/checkbox" /> 
    </TableRow>
    <LinearLayout android:paddingTop="10px" android:layout_width="fill_parent" android:gravity="center_horizontal">

            <Button android:layout_width="wrap_content" android:id="@+id/submit"
                android:layout_height="wrap_content" android:text="Login"
                android:gravity="center"  />





    </LinearLayout>

</TableLayout>

Don't set view's size or text's size in px . 不要在px设置视图的大小或文本的大小。 Use dp . 使用dp

Check the official documentation . 查看官方文档

You should create value/dimens.xml file for mobile and value-sw600dp/dimes.xml for tablet. 您应该为mobile创建value / dimens.xml文件,为平板电脑创建value-sw600dp / dimes.xml。 Next you should write down there different dimensions for each item in your layout. 接下来,您应该在布局中为每个项目写下不同的尺寸。 Like this: 像这样:

File values/dimens.xml : 文件值/ dimens.xml:

<resources>
    <dimen name="sapuser_width">150dip</dimen>
</resources>

File values-sw600dp/dimens.xml 文件值-sw600dp / dimens.xml

<resources>
    <dimen name="sapuser_width">300dip</dimen>
</resources>

After that you should write down references on dimensions. 之后,您应该记下尺寸参考。 For example 例如

<EditText android:id="@+id/sapuser" android:hint="Required"
            android:layout_column="2" android:width="@dimen/sapuser_width" android:paddingLeft="5dip"
             android:layout_marginRight="15dip" android:text="" android:singleLine="true" />

Note that for 7 inch and 10 inch you should use different values: 请注意,对于7英寸和10英寸,您应使用不同的值:

  • For 7 inch - values-sw600dp 对于7英寸 - 值 - sw600dp
  • For 10 inch - values-sw720dp 对于10英寸 - 值-sw720dp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM