当前位置: 首页 > news >正文

汕头模版网站建设正规手游代理平台有哪些

汕头模版网站建设,正规手游代理平台有哪些,个人做旅游网站,用WordPress做网站入门课一,百分比布局库android-percent-support介绍 百分比布局库中提供了两种布局可以设置百分比:PercentRelativeLayout、PercentFrameLayout。 这两个百分比布局都有以下九个布局属性,值都是用百分比来表示宽度、高度、margin值,使用…

一,百分比布局库android-percent-support介绍
百分比布局库中提供了两种布局可以设置百分比:PercentRelativeLayout、PercentFrameLayout。

这两个百分比布局都有以下九个布局属性,值都是用百分比来表示宽度、高度、margin值,使用时候需要父布局为百分比布局,child控件才可以使用这九个布局属性:

app:layout_heightPercent
app:layout_widthPercent
app:layout_marginPercent
app:layout_marginTopPercent
app:layout_marginBottomPercent
app:layout_marginLeftPercent
app:layout_marginRightPercent
app:layout_marginStartPercent
app:layout_marginEndPercent
可以看到支持宽高,以及margin。

也就是说,大家只要在开发过程中使用PercentRelativeLayout、PercentFrameLayout替换FrameLayout、RelativeLayout即可。

二,百分比布局使用
关于使用,其实及其简单,并且github上也有例子,android-percent-support-lib-sample。我们就简单过一下:

首先记得在build.gradle添加:

compile 'com.android.support:percent:22.2.0'


1

(一) PercentFrameLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayoutxmlns: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"><TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="left|top"android:background="#44ff0000"android:text="width:30%,height:20%"app:layout_heightPercent="20%"android:gravity="center"app:layout_widthPercent="30%"/><TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="right|top"android:gravity="center"android:background="#4400ff00"android:text="width:70%,height:20%"app:layout_heightPercent="20%"app:layout_widthPercent="70%"/><TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_gravity="bottom"android:background="#770000ff"android:text="width:100%,height:10%"android:gravity="center"app:layout_heightPercent="10%"app:layout_widthPercent="100%"/></android.support.percent.PercentFrameLayout>


3个TextView,很简单,直接看效果图: 
(二) PercentRelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayoutxmlns: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"android:clickable="true"><TextViewandroid:id="@+id/row_one_item_one"android:layout_width="0dp"android:layout_height="0dp"android:layout_alignParentTop="true"android:background="#7700ff00"android:text="w:70%,h:20%"android:gravity="center"app:layout_heightPercent="20%"app:layout_widthPercent="70%"/><TextViewandroid:id="@+id/row_one_item_two"android:layout_width="0dp"android:layout_height="0dp"android:layout_toRightOf="@+id/row_one_item_one"android:background="#396190"android:text="w:30%,h:20%"app:layout_heightPercent="20%"android:gravity="center"app:layout_widthPercent="30%"/><ImageViewandroid:id="@+id/row_two_item_one"android:layout_width="match_parent"android:layout_height="0dp"android:src="@drawable/tangyan"android:scaleType="centerCrop"android:layout_below="@+id/row_one_item_one"android:background="#d89695"app:layout_heightPercent="70%"/><TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:layout_below="@id/row_two_item_one"android:background="#770000ff"android:gravity="center"android:text="width:100%,height:10%"app:layout_heightPercent="10%"app:layout_widthPercent="100%"/></android.support.percent.PercentRelativeLayout>


 


(三) 使用注意
其实PercentRelativeLayout 和PercentFrameLayout就是多了九个布局属性的RelativeLayout 和FrameLayout,用法完全和这两个布局一样,不过只有父布局是百分比布局(PercentRelativeLayout和PercentFrameLayout )的时候,child才能使用百分比布局属性进行布局,否则无效,如:

<android.support.percent.PercentRelativeLayout 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">
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/button"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:text="width=50%"app:layout_widthPercent="50%" /></LinearLayout>
</android.support.percent.PercentRelativeLayout>



这样设置Button的宽度并不会是父布局宽度的一半,因为child用百分比只对父布局是百分比布局才有效。三、实现PercentLinearlayout
(一) PercentLinearLayout

package com.juliengenoud.percentsamples;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 zhy 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);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){mPercentLayoutHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);super.onMeasure(widthMeasureSpec, heightMeasureSpec);if (mPercentLayoutHelper.handleMeasuredStateTooSmall()){super.onMeasure(widthMeasureSpec, heightMeasureSpec);}}@Overrideprotected void onLayout(boolean changed, int l, int t, int r, int b){super.onLayout(changed, l, t, r, b);mPercentLayoutHelper.restoreOriginalParams();}@Overridepublic LayoutParams generateLayoutParams(AttributeSet attrs){return new LayoutParams(getContext(), attrs);}public static class LayoutParams extends LinearLayout.LayoutParamsimplements PercentLayoutHelper.PercentLayoutParams{private PercentLayoutHelper.PercentLayoutInfo mPercentLayoutInfo;public LayoutParams(Context c, AttributeSet attrs){super(c, attrs);mPercentLayoutInfo = PercentLayoutHelper.getPercentLayoutInfo(c, attrs);}@Overridepublic PercentLayoutHelper.PercentLayoutInfo getPercentLayoutInfo(){return mPercentLayoutInfo;}@Overrideprotected 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"?><com.juliengenoud.percentsamples.PercentLinearLayoutxmlns: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"android:orientation="vertical"><TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:background="#ff44aacc"android:text="width:60%,height:5%"android:textColor="#ffffff"app:layout_heightPercent="5%"app:layout_marginBottomPercent="5%"app:layout_widthPercent="60%"/><TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:background="#ff4400cc"android:gravity="center"android:textColor="#ffffff"android:text="width:70%,height:10%"app:layout_heightPercent="10%"app:layout_marginBottomPercent="5%"app:layout_widthPercent="70%"/><TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:background="#ff44aacc"android:gravity="center"android:text="width:80%,height:15%"android:textColor="#ffffff"app:layout_heightPercent="15%"app:layout_marginBottomPercent="5%"app:layout_widthPercent="80%"/><TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:background="#ff4400cc"android:gravity="center"android:text="width:90%,height:5%"android:textColor="#ffffff"app:layout_heightPercent="20%"app:layout_marginBottomPercent="10%"app:layout_widthPercent="90%"/><TextViewandroid:layout_width="match_parent"android:layout_height="0dp"android:background="#ff44aacc"android:gravity="center"android:text="width:100%,height:25%"android:textColor="#ffffff"app:layout_heightPercent="25%"app:layout_marginBottomPercent="5%"/></com.juliengenoud.percentsamples.PercentLinearLayout>


我们纵向排列的几个TextView,分别设置宽/高都为百分比,且之间的间隔为5%p。 


四,固定比例属性 layout_aspectRatio
注意:layout_aspectRatio属性需要在23.3.0版本以上才能使用

详细解释请见:http://blog.csdn.net/zcn596785154/article/details/76855499

PercentLayout是百分比控件, 使用百分比属性创建控件. 除了常用的百分比, 也可以使用固定比例进行布局(aspect ratio)

PercentLayout布局, 提供宽度和比例, 自动适配高度.

<android.support.percent.PercentRelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@+id/main_text"><ImageViewandroid:layout_width="0dp"android:layout_height="0dp"android:background="#FF1493"app:layout_aspectRatio="@fraction/header_aspectRatio"app:layout_widthPercent="50%"/></android.support.percent.PercentRelativeLayout>



比例的资源文件, fractions.xml.

<resources><item name="header_aspectRatio" type="fraction">178%</item>
</resources>


178%的含义是16:9.  //宽:高

文章参考:

Android 百分比布局库(percent-support-lib) 解析与扩展

PercentLayout的固定比例

Android百分比布局支持库(android-percent-support)
 

http://www.lbrq.cn/news/2474101.html

相关文章:

  • 哪个网站做批韩国护肤品批发seo专业培训费用
  • 淮安网站建设自助快速建站
  • 品牌英语扬州网站seo
  • 外贸网站模板大全网页制作代码大全
  • 作业不会做网站上找人做靠谱吗朋友圈广告推广
  • 云南建设网站首页青岛百度竞价
  • 商洛免费做网站公司最新推广方法
  • 网站建设 技术支持 阿里太原百度seo排名
  • 网站开发 发票哈尔滨推广优化公司
  • 个人网站设计规划书个人主页网页设计模板
  • 电商网站建站怎样做自己的网站
  • 产品网站别人是如何做优化的百度推广营销中心
  • 博物馆网站做的最好的谷歌seo详细教学
  • 网站建设 百度推广网站推广策划方案
  • 做网站推广需要花多少钱网奇seo培训官网
  • 全是图片的网站怎么做seo网络营销推广方式包括
  • 网站建设海南手机端seo
  • 最好的外贸网站建设引擎搜索技巧
  • 全国开发一个网站需要多少钱全国疫情的最新数据
  • 网站建设网站管理如何推广网站运营
  • 做pc端的网站首页尺寸是多少百度人工投诉电话是多少
  • 信息网查询关于进一步优化当前疫情防控措施
  • 网站建设论坛报告今日刚刚发生的新闻
  • 常州建设局官方网站友情链接什么意思
  • 山东省住房和城乡城乡建设厅网站微信群发软件
  • p2p网站建设方案网站建设方案优化
  • 政府网站图解怎么做爱站长尾关键词挖掘工具
  • 怎么在国税网站上做实名认证吗app如何推广
  • 做家装网站客户来源多吗谷歌seo和百度seo
  • 创建全国文明城市建议简短seo是什么字
  • 数据库索引详解:原理、设计原则与应用场景
  • MongoDB数据模型
  • RS485转Profinet网关配置指南:高效启动JRT激光测距传感器测量模式
  • 【大模型实战】提示工程(Prompt Engineering)
  • OpenCV 图像变换全解析:从镜像翻转到仿射变换的实践指南
  • 期待更好的发展