安卓百分比布局的使用
来源:互联网 发布:阿里云rds数据库 编辑:程序博客网 时间:2024/05/29 01:55
安卓百分比布局的使用: 在gradle中加此行代码 compile 'com.zhy:percent-support-extends:1.0.1'
他有PercentRelativeLayout、PercentFrameLayout两个类,
我们可以根据他们延伸出其他布局 比如线性布局(LinearL
package com.example.mrzhang.myapplication.MyControl;import android.content.Context;import android.content.res.TypedArray;import android.support.percent.PercentLayoutHelper;import android.util.AttributeSet;import android.view.ViewGroup;import android.widget.LinearLayout;/** * Created by MrZhang on 15/6/30. * 自定义组件 实现线性百分比布局 */public class PercentLinearLayout extends LinearLayout{ private PercentLayoutHelper mPercentLayoutHelper; public PercentLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); mPercentLayoutHelper = new PercentLayoutHelper(this); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { mPercentLayoutHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (mPercentLayoutHelper.handleMeasuredStateTooSmall()) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); mPercentLayoutHelper.restoreOriginalParams(); } @Override public LayoutParams generateLayoutParams(AttributeSet attrs) { return new LayoutParams(getContext(), attrs); } public static class LayoutParams extends LinearLayout.LayoutParams implements PercentLayoutHelper.PercentLayoutParams { private PercentLayoutHelper.PercentLayoutInfo mPercentLayoutInfo; public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); mPercentLayoutInfo = PercentLayoutHelper.getPercentLayoutInfo(c, attrs); } @Override public PercentLayoutHelper.PercentLayoutInfo getPercentLayoutInfo() { return mPercentLayoutInfo; } @Override protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) { PercentLayoutHelper.fetchWidthAndHeight(this, a, widthAttr, heightAttr); } //可加也可以不加// public LayoutParams(int width, int height) {// super(width, height);// }////// public LayoutParams(ViewGroup.LayoutParams source) {// super(source);// }//// public LayoutParams(MarginLayoutParams source) {// super(source);// } }}
<?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" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.mrzhang.myapplication.MyControl.PercentLinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:gravity="center" android:id="@+id/text" android:layout_width="0dp" android:layout_height="0dp" android:background="#000000" android:text="textview" android:textColor="#ffffff" app:layout_heightPercent="10%" app:layout_widthPercent="100%" /> <TextView android:id="@+id/tiaozuan" android:gravity="center" android:layout_width="0dp" android:layout_height="0dp" android:background="#ff0000" android:text="textview" android:textColor="#ffffff" app:layout_heightPercent="10%" app:layout_widthPercent="100%" /> <Button android:gravity="center" android:id="@+id/xiangce" android:layout_width="0dp" android:layout_height="0dp" android:text="相册" app:layout_heightPercent="10%" app:layout_widthPercent="100%" /> <ImageView android:id="@+id/imageview" android:layout_width="0dp" android:layout_height="0dp" app:layout_heightPercent="30%" android:layout_gravity="center" app:layout_widthPercent="50%"/> <com.example.mrzhang.myapplication.MyAsynchronization.NumberKeyboardView android:id="@+id/numbers" android:layout_width="0dp" android:layout_height="0dp" android:gravity="center" android:layout_gravity="center_horizontal" app:layout_heightPercent="40%" app:layout_widthPercent="100%" /> </com.example.mrzhang.myapplication.MyControl.PercentLinearLayout></LinearLayout>
阅读全文
0 0
- 安卓百分比布局的使用
- 安卓 百分比布局
- 安卓百分比布局
- 百分比布局的使用
- 百分比布局的使用
- 百分比布局的使用
- 安卓设备适配终极杀器-谷歌百分比布局库的使用
- 完美适配之安卓百分比布局使用,治好广大安卓程序员的头疼病
- Android Percent Layout 安卓百分比布局
- 安卓百分比布局之RelativeLayout
- Android百分比布局的使用
- 安卓布局的使用
- 安卓百分比布局---很好的解决屏幕适配问题
- Android 百分比布局库的使用
- android 百分比布局percentFrameLayout,percentRelativeLayout的使用
- 安卓百分比布局增强版转换工具Px2Percent.jar
- CSS 使用百分比布局
- 安卓百分百布局的使用
- 快速排序
- 支持向量机(SVM)算法
- 脚本rsync
- ROC与AUC的计算
- 浅谈iOS设计模式
- 安卓百分比布局的使用
- BZOJ 1324: Exca王者之剑/BZOJ 1475: 方格取数 最大权独立集 最小割
- 自定义progressbar样式
- 素数求和问题
- Maven插件之portable-config-maven-plugin(不同环境打包)
- style 实现全屏和AppCompat does not support the current theme features错误的解决
- 软件模块划分原理
- swift3.0获取友盟device_token
- 生成&调用自己的静态库lib