簡體   English   中英

Android應用程序自適應(適合所有​​屏幕尺寸)

[英]Android application Responsive(Fit for all screen sizes)

我正在開發一個具有按鈕和圖像的android應用程序。我需要使其具有響應性。如果我使用較大的設備(如平板電腦),則顯示的控件非常小。而在橫向模式下使用時,它會顯示一半的控件。或項目。我該如何克服這個問題並使我的應用程序對所有設備做出響應。我在下面附加了我的XML代碼之一。

<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>

對於響應式設計,請采取以下措施:1)不要提供像125dp這樣的硬代碼值,而不要提供用戶wrap_content或match_parent屬性2)將圖像置於res可繪制狀態下,按照分辨率OS來獲取適合其分辨率的圖像,例如,用於平板電腦設計,創建drawable-sw600文件夾在res下,將平板電腦圖片放在下面。 3)值相同->尺寸創建具有特定文件夾名稱的不同尺寸文件。 例如,用於數位板的values-sw600 4)使用ScrollView控件可避免在橫向模式下截屏。 有關更多詳細信息和指南,請訪問http://developer.android.com/guide/practices/screens_support.htmlhttp://developer.android.com/training/multiscreen/screendensities.html

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

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

同樣,在橫向模式下,您的小部件看起來超出了屏幕高度。 一種快速的解決方案是將LinearLayout放在ScrollView以便它在橫向時滾動並看到所有控件。 但是理想的方法是為橫向和縱向模式設置不同的布局。

如果使用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. 多屏設計

  2. 支持不同的屏幕尺寸

  3. 支持多屏

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM