2015-11-02 181 views
0

我正在開發一個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> 

回答

0

您可以從下面提到的資源開始。在設計和開發應用程序時,爲所有屏幕尺寸製作應用程序都需要特別考慮。

您必須處理圖像以使其與不同的屏幕尺寸保持一致。這將通過平板電腦中的非常小的控件來解決問題。

此外,它看起來像在橫向模式下你的小部件超出屏幕高度。快速解決方案是將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
0

對於響應式設計採取 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