屏幕適配

屏幕適配

什麼是屏幕適配?

  • Android中屏幕適配就是通過對尺寸單位、圖片、文字、佈局這四種類型的資源進行合理的設計和規劃,在佈局時合理利用各種類型的資源,讓佈局擁有適應能力,能在各種設備下保持良好的展現效果。

尺寸適配怎麼做?

  • 在res中創建一個values-960*540和values-1180*1184文件夾中,各創建一個dimens文件並創建不同佈局代碼,在通過調用就可以實現了。
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="app_width">400dp</dimen>
</resources>

圖片適配怎麼做?

  • 在res中創建一個mipmap文件夾中,創建一個ic_launcher.xml文件,放入相對應圖片在通過調用就可以實現了。

什麼是9.PNG

  • 這是安卓開發裏面的一種特殊的圖片
    這種格式的圖片在android 環境下具有自適應調節大小的能力。
    (1)允許開發人員定義可擴展區域,當需要延伸圖片以填充比圖片本身更大區域時,可擴展區的內容被延展(上,左)。
    (2)允許開發人員定義內容顯示區,用於顯示文字或其他內容(右下)。

文字國際化怎麼做?

  • 在res中創建一個values-en文件夾中,創建一個Strings文件,在通過調用就可以實現了。
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">你好</string>
    <string name="hello_blank_fragment">Hello blank fragment</string>
    <string name="btn_text">今天</string>
</resources>

橫豎屏適配怎麼做?

  • 在res中創建一個layout-land文件夾,創建一個layout文件,在通過調l用就可以實現了。
    • 原layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.zwzz.myapplication.test3.downActivity">


      <EditText
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="請輸入倒計時   S"
           android:id="@+id/et_time"
          />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="倒計時"
        android:id="@+id/tv_down"
        android:layout_gravity="center"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="點擊倒計時開始"
        android:id="@+id/bt_downlad"
        />
</LinearLayout>
  • layout-land 中layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.zwzz.myapplication.test3.downActivity">



    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="倒計時"
        android:id="@+id/tv_down"
        android:layout_gravity="center"
        />

</LinearLayout>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章