Android Studio 控件的百分比布局

  • 在安卓开发控件的百分比布局学习中,由于我参考的是第一行代码中的资源,其中的Android studio版本过低,导致的一些错误,花了好长时间来解决它。这里我用的是Android studio 3.5.3

**首先是依赖的添加,由于我使用的版本相比参考书中的高,Android studio中已经不支持在compile,**所以我在模块级build.gradle添加如下的依赖:

11 implementation 'androidx.percentlayout:percentlayout:1.0.0' 2 31 dependencies { 42 implementation 'androidx.percentlayout:percentlayout:1.0.0' 53 implementation fileTree(dir: 'libs', include: ['*.jar']) 64 implementation 'androidx.appcompat:appcompat:1.1.0' 75 implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 86 testImplementation 'junit:junit:4.12' 97 androidTestImplementation 'androidx.test.ext:junit:1.1.0' 108 androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 119 }

 **后面就是对layout中的 *.xml 文件进行修改,**这里的话百分比布局中分 PercentRelativeLayout PercentFrameLayout 两种****我采用的是PercentRelativeLayout,代码如下

1 1 <androidx.percentlayout.widget.PercentRelativeLayout 2 2 xmlns:android="http://schemas.android.com/apk/res/android" 3 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 4 android:layout_width="match_parent" 5 5 android:layout_height="match_parent"> 6 6 7 7 <TextView 8 8 android:id="@+id/row_one_item_one" 9 9 android:layout_width="0dp" 1010 android:layout_height="0dp" 1111 android:layout_alignParentTop="true" 1212 android:background="#7700ff00" 1313 android:text="w:70%,h:20%" 1414 android:gravity="center" 1515 app:layout_heightPercent="20%" 1616 app:layout_widthPercent="70%"/> 1717 1818 <TextView 1919 android:id="@+id/row_one_item_two" 2020 android:layout_width="0dp" 2121 android:layout_height="0dp" 2222 android:layout_toRightOf="@+id/row_one_item_one" 2323 android:background="#396190" 2424 android:text="w:30%,h:20%" 2525 app:layout_heightPercent="20%" 2626 android:gravity="center" 2727 app:layout_widthPercent="30%"/> 2828 2929 3030 <ImageView 3131 android:id="@+id/row_two_item_one" 3232 android:layout_width="match_parent" 3333 android:layout_height="0dp" 3434 android:src="@drawable/img_1" 3535 android:scaleType="centerCrop" 3636 android:layout_below="@+id/row_one_item_one" 3737 android:background="#d89695" 3838 app:layout_heightPercent="70%"/> 3939 4040 <TextView 4141 android:layout_width="0dp" 4242 android:layout_height="0dp" 4343 android:layout_below="@id/row_two_item_one" 4444 android:background="#770000ff" 4545 android:gravity="center" 4646 android:text="width:100%,height:10%" 4747 app:layout_heightPercent="10%" 4848 app:layout_widthPercent="100%"/> 4949 5050 5151 </androidx.percentlayout.widget.PercentRelativeLayout>

这里我参照了一位博友的博客

http://blog.csdn.net/lmj623565791/article/details/46695347

想了解其中的源码分析可以参考这个博客。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )