Android適配--百分比的適配,android適配百分比

來源:互聯網
上載者:User

Android適配--百分比的適配,android適配百分比

首先,需要添加com.android.support:percent:24.1.1 包,版本隨意。

dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:24.1.1'    compile 'com.android.support:percent:24.1.1'}

}

 

 

 

  這個包給我們提供了PercentRelativeLayout以及PercentFrameLayout兩種布局,

  支援的屬性有layout_widthPercentlayout_heightPercent、 
  layout_marginPercentlayout_marginLeftPercent、 
  layout_marginTopPercentlayout_marginRightPercent、 
  layout_marginBottomPercentlayout_marginStartPercentlayout_marginEndPercent

     大概的內容就有這些,下面貼上一段代碼及

<?xml version="1.0" encoding="utf-8"?><android.support.percent.PercentRelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    xmlns:app="http://schemas.android.com/apk/res-auto"    tools:context="com.example.administrator.mingyishijia.LoginActivity">    <android.support.v7.widget.Toolbar        xmlns:app="http://schemas.android.com/apk/res-auto"        app:navigationIcon="@mipmap/left_back_gray_icon"        android:id="@+id/activity_main_toolbar"        android:layout_height="wrap_content"        android:layout_width="match_parent"        android:minHeight="?attr/actionBarSize"        android:background="?attr/colorPrimary"></android.support.v7.widget.Toolbar>       <EditText        android:layout_width="0dp"        android:layout_height="0dp"        app:layout_heightPercent="8%"        app:layout_widthPercent="70%"        android:background="@drawable/usereditor_background"        android:id="@+id/userName"        android:gravity="center"        android:layout_below="@+id/activity_main_toolbar"        app:layout_marginTopPercent="10%"        android:layout_centerHorizontal="true"        android:hint="請輸入帳號"/>    <EditText        android:layout_width="0dp"        android:layout_height="0dp"        app:layout_heightPercent="8%"        app:layout_widthPercent="70%"        android:background="@drawable/usereditor_background"        android:id="@+id/password"        android:layout_below="@+id/userName"        android:gravity="center"        app:layout_marginTopPercent="2%"        android:layout_centerHorizontal="true"        android:hint="請輸入密碼"/>    <Button        android:layout_width="0dp"        android:layout_height="0dp"        app:layout_heightPercent="8%"        app:layout_widthPercent="70%"        android:background="@drawable/login_button_background"        android:id="@+id/login"        android:layout_below="@+id/password"        android:text="登    錄"        android:textSize="18sp"        android:textColor="#ffffff"        android:layout_centerHorizontal="true"        app:layout_marginTopPercent="5%" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:id="@+id/forgetPassword"        android:layout_below="@+id/login"        android:layout_alignLeft="@+id/login"        app:layout_marginTopPercent="2%"        android:text="忘記密碼"        android:textSize="12sp"        android:textColor="#1a81ff"/>    <LinearLayout        android:layout_width="0dp"        android:layout_height="wrap_content"        app:layout_widthPercent="90%"        android:id="@+id/l1"        android:orientation="horizontal"        android:clickable="false"        android:layout_centerHorizontal="true"        android:layout_below="@+id/forgetPassword"        app:layout_marginTopPercent="5%">        <View            android:layout_width="match_parent"            android:layout_height="1dp"            android:background="#000000"            android:layout_weight="1.1"            android:layout_gravity="center"/>        <TextView            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="或使用以下方式登入"            android:textSize="12sp"            android:gravity="center"/>        <View            android:layout_width="match_parent"            android:layout_height="1dp"            android:background="#000000"            android:layout_weight="1.1"            android:layout_gravity="center"/>    </LinearLayout>    <LinearLayout        android:layout_width="0dp"        android:layout_height="0dp"        app:layout_heightPercent="15%"        app:layout_widthPercent="75%"        android:layout_centerHorizontal="true"        android:orientation="horizontal"        android:layout_below="@+id/l1"        app:layout_marginTopPercent="5%"        android:id="@+id/linearLayout">        <android.support.percent.PercentRelativeLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_weight="1">            <ImageView                android:layout_width="0dp"                android:layout_height="0dp"                app:layout_heightPercent="60%"                app:layout_widthPercent="100%"                android:scaleType="fitCenter"                android:id="@+id/iv1"                android:src="@mipmap/weixin"/>            <TextView                android:layout_width="0dp"                android:layout_height="0dp"                app:layout_heightPercent="40%"                app:layout_widthPercent="100%"                android:layout_below="@+id/iv1"                android:text=""                android:gravity="center"/>        </android.support.percent.PercentRelativeLayout>        <android.support.percent.PercentRelativeLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_weight="1">            <ImageView                android:layout_width="0dp"                android:layout_height="0dp"                app:layout_heightPercent="60%"                app:layout_widthPercent="100%"                android:scaleType="fitCenter"                android:id="@+id/iv2"                android:src="@mipmap/aqq1"/>            <TextView                android:layout_width="0dp"                android:layout_height="0dp"                app:layout_heightPercent="40%"                app:layout_widthPercent="100%"                android:layout_below="@+id/iv2"                android:text="QQ"                android:gravity="center"/>        </android.support.percent.PercentRelativeLayout>        <android.support.percent.PercentRelativeLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_weight="1">            <ImageView                android:layout_width="0dp"                android:layout_height="0dp"                app:layout_heightPercent="60%"                app:layout_widthPercent="100%"                android:scaleType="fitCenter"                android:id="@+id/iv3"                android:src="@mipmap/dingding"                />            <TextView                android:layout_width="0dp"                android:layout_height="0dp"                app:layout_heightPercent="40%"                app:layout_widthPercent="100%"                android:layout_below="@+id/iv3"                android:text="DingTalk"                android:gravity="center"/>        </android.support.percent.PercentRelativeLayout>    </LinearLayout></android.support.percent.PercentRelativeLayout>

         

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.