Android应用程序响应(适合所有​​屏幕尺寸)

问题描述:

我正在开发一个android应用程序,它有一个按钮和images.I需要使它响应。如果我使用更大的设备,如平板电脑,它显示的控件很小。当我在横向模式下使用时,它会显示一半的控件或项目。我如何克服这一点并使我的应用程序能够响应所有设备。我在下面附加了我的一个XML代码。Android应用程序响应(适合所有​​屏幕尺寸)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_margin="10dp" 
android:orientation="vertical" 
> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="fill_parent" 
    android:layout_height="125dp" 
    android:layout_marginTop="50dp" 
    android:layout_weight="0.01" 
    android:adjustViewBounds="true" 
    >   
</ImageView> 

<LinearLayout 
    android:id="@+id/layButtonH" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.01" 
    android:layout_marginTop="20dp" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <Button 
    android:id="@+id/addnew" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=" ADD NEW  " 
    android:background="@drawable/button_shape" 
    android:textColor="#FFFFFF"/> 


    <Button 
     android:id="@+id/open" 
     android:background="@drawable/button_shape_cancel" 
     android:layout_marginTop="30dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="  OPEN   " 
     android:textColor="#FFFFFF" /> 
    <Button 
     android:id="@+id/Register" 
     android:background="@drawable/button_shape_cancel" 
     android:layout_marginTop="30dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="  LOGIN  " 
     android:textColor="#FFFFFF" /> 


</LinearLayout> 

您可以从下面提到的资源开始。在设计和开发应用程序时,为所有屏幕尺寸制作应用程序都需要特别考虑。

您必须处理图像以使其与不同的屏幕尺寸保持一致。这将通过平板电脑中的非常小的控件来解决问题。

此外,它看起来像在横向模式下你的小部件超出屏幕高度。快速解决方案是将LinearLayout放在ScrollView之内,以便在横向滚动时可以滚动,并且可以看到所有的控件。但理想的方式是对风景和肖像模式进行不同的布局。

如果使用滚动型的代码如下:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

<!-- Your remaining xml elements --> 

</ScrollView> 

编号:

  1. Design for multiple screens

  2. Supporting different screen sizes

  3. Supporting multiple screens

对于响应式设计采取 1)不要给硬编码值等为125dp,而不是用户WRAP_CONTENT或match_parent财产 2)将图像清晰度下每分辨率OS采取适合的图像作为绘制对于其分辨率,例如平板电脑设计在res下创建drawable-sw600文件夹,并将平板电脑图像放在它下面。 3)相同的值 - >维创建具有特定文件夹名称的不同维度文件。例如用于平板电脑的值为sw600的设备 4)使用ScrollView控件来避免横向模式下的屏幕切割。 欲了解更多详情和指南,请访问http://developer.android.com/guide/practices/screens_support.htmlhttp://developer.android.com/training/multiscreen/screendensities.html