Android适配之百分比的简单用法

  我是一枚IT界的小学生,本文也是针对百分比的简单用法以及总结,如果想要深入研究请移步至大神的博客,下面开始:

  首先,需要添加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="钉钉"
                android:gravity="center"/>
        </android.support.percent.PercentRelativeLayout>

    </LinearLayout>

</android.support.percent.PercentRelativeLayout>

        

  希望能对想我一样的初学者有帮助。

				
时间: 2024-07-31 14:32:51

Android适配之百分比的简单用法的相关文章

Android中AsyncTask的简单用法【转】

在开发Android移动客户端的时候往往要使用多线程来进行操作,我们通常会将耗时的操作放在单独的线程执行,避免其占用主线程而给用户带来不好的用户体验.但是在子线程中无法去操作主线程(UI 线程),在子线程中操作UI线程会出现错误.因此android提供了一个类Handler来在子线程中来更新UI线程,用发消息的机制更新UI界面,呈现给用户.这样就解决了子线程更新UI的问题.但是费时的任务操作总会启动一些匿名的子线程,太多的子线程给系统带来巨大的负担,随之带来一些性能问题.因此android提供了

Android WIFI 简单用法

随着Wifi的普及,在开发App的时候对wifi的考虑越来越多了.例如程序的升级在wifi下可以省很多流量,在通信软件中的视频通话.可以实现高画质的传输等等,Android提供了WifiManager类来帮助开发者们管理Wifi.下面就简单来说一下WifiManager的简单用法把. 权限: 为了使用WfiManager 我们需要在Androidmanifest.xml 加入权限: //本例中使用了前两个.具体请按照需要添加权限. <uses-permission android:name=&quo

Android中资源文件中的字符串数组string-array简单用法

在Android中,用string-array是一种简单的提取XML资源文件数据的方法. 例子如下: 把相应的数据放到values文件夹的strings.xml文件里,或是其他自定义的xml中都可以,以下操作方法相同. <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="sports"> <item>足球<

【android】Socket简单用法

原文地址:http://www.cnblogs.com/harrisonpc/archive/2011/03/31/2001565.html Socket通常也称做”套接字“,用于描述IP地址和端口,废话不多说,它就是网络通信过程中端点的抽象表示.值得一提的是,Java在包java.net中提供了两个类Socket和ServerSocket,分别用来表示双向连接的客户端和服务端.这是两个封装得非常好的类,使用起来很方便! 下面将首先创建一个SocketServer的类作为服务端如下,该服务端实现

Android简单的文件浏览器,ListActivity的简单用法

2014-07-29 13:39:09MainActivity.java package com.example.sample_4_21; import java.io.File; import java.util.ArrayList; import java.util.List; import android.app.AlertDialog; import android.app.ListActivity; import android.content.DialogInterface; imp

ViewPager的简单用法+适配器+监听器的介绍

之前的actionbar+fragment文章中写过viewpager的简单用法,但因为是融合的文章,所以今天把viewpager提取出来写了.方便查询浏览~ 思路: 1.在布局文件中设置viewpager控件 2.在acitvity中找到它 3.自定义一个适配器,这个适配器需要一个list<View>来构造 4.定义一个list<View>来放入几个view,并用其来初始化适配器 5.给viewPager来设置适配器和监听器 实现: 1.布局文件,这里放一个指示文字.实际中可以用

WebView的一些简单用法

一直想写一个关于 WebView 控件的 一些简单运用,都没什么时间,这次也是挤出时间写的,里面的一些基础知识就等有时间再更新讲解一下,今天就先把项目出来做一些简单介绍,过多的内容可以看我的源码,都传到github上了. 下面是项目的效果图: 应用用到的是 MVP 设计模式,对这种模式还不太了解的可以先自行google一下,不然项目估计会看的晕,虽然我的代码都很简洁的. 对于MVP 可以带着一个思路看源码,那就是 activity(或其他组件)通过 xxPresenter 去拿数据,拿到数据 在

iOS block-base 动画简单用法+关键帧动画设置线性变化速度的问题

本文转载至 http://www.tuicool.com/articles/aANBF3m 时间 2014-12-07 20:13:37  segmentfault-博客原文  http://segmentfault.com/blog/alan/1190000002411296 iOS的各种动画相漂亮,相信这是吸引很多人买iPhone的原因之一.不仅如此,这还是吸引我做iOS开发的一大原因,因为在iOS上给界面实现一些像样的动画实在是太轻松了! 这里就介绍一下iOS的block-based an

C++ double转string类型以及MFC控件简单用法

这两天项目需要,测试c++库里面内容.生成jar再给Android调用.我没有学过C++,现在开始记录C++简单用法.测试时候一般都是使用mfc程序来测试,要输入值,显示结果吗.我用的编译环境vs2008. 一.double 转string #include <string> CString strResultx; strResultx.Format(_T("x:%.4f\n"), 89.7887878); 转换结果还是放在strResultx 2.两个字符串相连 CStr