GridLayout在API21之前的兼容

GridLayout在API21之前的兼容问题:GridLayout在API21时引入了android:layout_columnWeight和android:layout_rowWeight来解决平分问题,但是api21前怎么办呢?解决:1.引入兼容包:compile’com.android.support:gridlayout-v7:23.0.0’2.为GridLayout设置权重:app:layout_column…

大家好,又见面了,我是你们的朋友全栈君。

问题:GridLayout在API21时引入了android:layout_columnWeight和android:layout_rowWeight来解决平分问题,但是api21前怎么办呢?

解决:

1.引入兼容包:

  compile 'com.android.support:gridlayout-v7:23.0.0'

2.为GridLayout设置权重:
app:layout_columnWeight app:layout_rowWeight (注意这里前缀是app因为21以前android是没有这个属性的)

以及行列跨越:app:layout_rowSpan app:layout_columnSpan

eg:

执行效果:
在这里插入图片描述

代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="com.nuctech.tr.trapp.activity.LoginActivity">
 
    <com.zhy.android.percent.support.PercentLinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:orientation="vertical">
 
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:orientation="vertical"
            app:layout_heightPercent="80%sh"
            app:layout_widthPercent="50%sw">
 
            <com.nuctech.tr.trapp.ui.FillBlankView
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:padding="5dp" />
 
            <android.support.v7.widget.GridLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                app:rowCount="4"
                app:columnCount="4"
               >
                 
 
                <Button
                    android:id="@+id/one"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="1" />
                  
 
                <Button
                    android:id="@+id/two"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="2" />
                   
 
                <Button
                    android:id="@+id/three"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="3" />
                   
 
                <Button
                    android:id="@+id/delete"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="退格" />
 
                <Button
                    android:id="@+id/four"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="4" />
                  
 
                <Button
                    android:id="@+id/five"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="5" />
                  
 
                <Button
                    android:id="@+id/six"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="6" />
 
                <Button
                    android:id="@+id/confirm"
 
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowSpan="3"
                    app:layout_rowWeight="3"
                    android:text="OK" />
 
                <Button
                    android:id="@+id/seven"
                    app:layout_columnWeight="1"
                    app:layout_gravity="fill"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="7" />
                  
 
                <Button
                    android:id="@+id/eight"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="8" />
                  
 
                <Button
                    android:id="@+id/nine"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="9" />
 
                <Button
                    android:id="@+id/removeall"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="X" />
                  
 
                <Button
                    android:id="@+id/zero"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="0" />
                  
 
                <Button
                    android:id="@+id/shutdown"
                    app:layout_columnWeight="1"
                    android:layout_margin="2dp"
                    app:layout_rowWeight="1"
                    android:text="S" />
            </android.support.v7.widget.GridLayout>
        </LinearLayout>
 
 
    </com.zhy.android.percent.support.PercentLinearLayout>
 
 
</RelativeLayout>

转载自:https://blog.csdn.net/lvwenbo0107/article/details/51769602

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/136554.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Java常用的设计模式

    Java常用的设计模式

    2021年5月5日
    107
  • 服务器cpu型号后面的字母,Intel 至强 E3服务器CPU后缀解读[通俗易懂]

    服务器cpu型号后面的字母,Intel 至强 E3服务器CPU后缀解读[通俗易懂]三、Intel至强E3服务器CPU后缀解读DIY玩家认识服务器CPU最多的无疑是E3神教,今天我们就总结下XeonE3神教的CPU后缀有什么特色。●V1-V5E3神教!从SNB开始,Intel就推出了E3系列至强CPU。由于阵脚一样,只需升级BIOS就能享用信仰级至强CPU,让2011年开始E3神教开始壮大。Intel也推出了E3的后续型号,与历代酷睿对应,从IvyBridge的V2到Sk…

    2022年5月29日
    49
  • 2019年2月10日训练日记

    2019年2月10日训练日记这是过完年第一天的训练,事情都忙完了,可以专心训练了,这个阶段开始训练关于stl容器的相关知识,然后做的题目都是英文题,完全看不懂,只能一点点的查单词翻译。做的很难受,而且很多知识都没有接触过,只能一点一点百度,看网课学习,所以一下午只a了一道题,不过收获还是蛮大的,以后英语一定要好好学,不然题意都看不懂,看不懂题怎么做题呢,然后就是要把stl的各类容器个好好练习,熟练掌握,做第一道题,我没有用s…

    2022年6月17日
    28
  • 大数据应用开发八大基本原则

    大数据应用开发八大基本原则·        大数据应用正在从概念走向现实,而企业在大数据应用开发时,软件的弹性(Resilient)正在成为决定大数据应用成败的关键因素。弹性差的应用无法应对大规模的数据集,在测试和运营中也缺乏透明度,而且也不安全。·        避免大数据应用在生产环境中掉链子的最佳办法就是在开发阶段就开发弹性应用,例如:健壮性、经过测试、可改变、可审计、高安全、可监控。·        可以说

    2022年6月4日
    36
  • 你要偷偷学python(所有人都能学的数据分析课)

    标题无意冒犯,就是觉得这个广告挺好玩的上面这张思维导图喜欢就拿走,反正我也学不了这么多文章目录前言欢迎来到我们的圈子并发与串行前言前期回顾:我要偷偷学Python(第十二天)第十二篇的项目还在持续更新中,哎,日理万机虽然谈不上,但是也是手忙脚乱。这不,自动表单生成是写完了,但是学校网络实在是受不了啊,2G,测试不了,就只能一直搁置在那边了。明天就可以去测试了,明天出学校去逛逛。今天的内容,可能很多小伙伴会没有听过,今天要讲多线程的概念,以及协程的使用。后面看看能不能讲一下scrapy框架..

    2022年4月16日
    42
  • lamp配置域名

    lamp配置域名windows访问的时候,记得把本机的windows/system32/drivers/etc/hosts文件中填上相应的配置(相当于dns)配置虚拟主机1)配置host文件/etc/hosts打开C:/windows/system32/drivers/etc/hosts文件增加域名记录如:192.168.9.38www.ec1.com192.168.9.38

    2022年6月6日
    24

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号