Android的布局支持百分比的设置进行开发,来学习如何去实现它,不过看起来会像网页的设置,比如宽度的设置属性是`layout_widthPercent`。在此之前,我们一般都会设置Linearlayout的weight权重来实现布局间的比例大小。

Percent support Library提供了两个新的类:

1.PercentRelativeLayout

2.PercentFrameLayout

 

创建新项目 

创建一个新的项目来测试,修改`build.gradle`,需要引入以下库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
`applyplugin:'com.android.application'
 
android {
 
compileSdkVersion23
 
buildToolsVersion"23.0.0"
 
defaultConfig {
 
applicationId"com.android.chaowen.percentdemo1"
 
minSdkVersion7
 
targetSdkVersion22
 
versionCode1
 
versionName"1.0"
 
}
 
buildTypes {
 
release {
 
minifyEnabledfalse
 
proguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
 
}
 
}
 
}
 
dependencies {
 
compile fileTree(dir:'libs',include: ['*.jar'])
 
compile'com.android.support:support-annotations:23.0.0'
 
compile'com.android.support:appcompat-v7:23.0.0'
 
compile'com.android.support:design:23.0.0'
 
compile'com.android.support:percent:23.0.0'
 
}

  创建布局

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"

tools:context=".MainActivity">

android:id="@+id/first"

android:background="@color/sa_green_dark"

app:layout_heightPercent="50%"

app:layout_marginLeftPercent="25%"

app:layout_marginTopPercent="25%"

app:layout_widthPercent="50%" />

android:layout_width="0dp"

android:layout_height="32dp"

android:layout_alignLeft="@id/first"

android:layout_alignStart="@id/first"

android:layout_alignRight="@id/first"

android:layout_alignEnd="@id/first"

android:layout_below="@id/first"

android:layout_marginTop="8dp"

android:background="@color/light_grey" />

比例大小是通过`heightPercent`和`widthPercent`属性来设置百分比大小值。完全属于`RelativeLayout`的扩展类,值得一提的是,

不再需要设置`layout_width`和`layout_height`,注意了,这是新的库使用方法,因为这两个属性会被自动加入了。

百度比也可以用于设置边距。唯一区别的只是采取了百分比值。

最后一点需要注意,在第二个view,并没有直接设置比例的大小,但是它的位置是相对于第一个view.

 

posted @ 2015-09-04 08:00 吴超文 阅读(573) 评论(0) 推荐(0) 编辑
摘要: Android-Empty-Layout:这个布局可以作用在Listview,Gridview,用于显示数据的是空的时候,可以提示友好的页面。这库可以显示页面出错,页面加载,页面是空。加载的动画页面也支持。项目主页:https://github.com/alamkanak/Android-Empty... 阅读全文
posted @ 2014-06-04 10:27 吴超文 阅读(1632) 评论(0) 推荐(0) 编辑
摘要: 1、点击PopupWindow外部区域时,PopupWindow消失popMenu = new PopupWindow(getApplicationContext()); popMenu.setWidth(LayoutParams.MATCH_PARENT); popMenu.setHeight(LayoutParams.MATCH_PARENT); popMenu.setBackgroundDrawable(new BitmapDrawable()); popMenu.setFocusable(true); popMenu.setOutsideTouchable(true);这里使... 阅读全文
posted @ 2013-10-09 10:14 吴超文 阅读(6507) 评论(0) 推荐(0) 编辑
摘要: 易信,它的UI还是很简洁,因此本人想模仿一下它,用了一天的时候来研究它的资源文件,终于被我写出来。先看下效果图吧。(一)首页的标题main_title.xml (二) 左边的滑动菜单实现通过SlidingMenu库与Fragment来实现当前最为流行的侧滑模式。其实涉及到的知识点有:1.SlidingMenu2.Fragment准备工作: 马上去下载这个开源库,https://github.com/jfeinstein10/SlidingMenu下载后的SlidingMenu文件,只需要在eclise导入library项目就行了。导入后,项目名默认就是librar... 阅读全文
posted @ 2013-08-26 11:07 吴超文 阅读(6310) 评论(18) 推荐(8) 编辑
摘要: 1.RefreshActionItem 基于ActionBarSherlock库的一个扩展,在标题栏右边显示多种刷新效果的UI按钮。 项目主页:https://github.com/ManuelPeinado/RefreshActionItem 阅读全文
posted @ 2013-07-13 09:21 吴超文 阅读(380) 评论(0) 推荐(0) 编辑
摘要: 在Android应用程序,使用动画效果,能带给用户更好的感觉。做动画可以通过XML或Android代码。本教程中,介绍使用XML来做动画。在这里,介绍基本的动画,如淡入,淡出,旋转等。效果:http://www.56.com/u82/v_OTM4MDk5MTk.html第一步: 创建anim文件夹放置动画xml文件 在res文件夹下,创建一个anim的子文件夹。 第二步: 加载动画 接着在Activity创建一个Animation类,然后使用AnimationUtils类加载动画xmlAnimation animFadein;@Overrideprotected vo... 阅读全文
posted @ 2013-07-10 23:55 吴超文 阅读(5575) 评论(0) 推荐(1) 编辑
摘要: 阅读全文
posted @ 2013-07-08 21:18 吴超文 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 效果图:创建Toast类package com.example.messageboxtest;import android.app.Activity;import android.content.Context;import android.os.Handler;import android.view.Gravity;import android.view.View;import android.view.ViewGroup;import android.view.animation.AlphaAnimation;import android.view.animation.Animation; 阅读全文
posted @ 2013-06-26 23:20 吴超文 阅读(2393) 评论(0) 推荐(0) 编辑
摘要: Action bar(动作栏)是一个导航控件,用以代替传统屏幕顶端的标题栏。对于新手来说,个性化一套美丽的Action Bar是一件麻烦的事。还好,国外开发者提供一套很独特的Action Bar个性化生成器(Android action bar style generator),就像平时用美图秀秀修图片一样,很容易就制作出一套Action Bar。点击这里进入Android action bar style generator 阅读全文
posted @ 2013-06-08 22:13 吴超文 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 在更新了最新的ADT22之后,就报错了。我直接把libs设为src就解决了。 阅读全文
posted @ 2013-05-29 17:58 吴超文 阅读(1576) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示