屏幕适配

屏幕适配

什么是屏幕适配?

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