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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Python小白的数学建模课-04.整数规划「建议收藏」

    Python小白的数学建模课-04.整数规划「建议收藏」整数规划与线性规划的差别只是变量的整数约束。问题区别一点点,难度相差千万里。选择简单通用的编程方案,让求解器去处理吧。『Python小白的数学建模课@Youcans』带你从数模小白成为国赛达人。1.从线性规划到整数规划1.1为什么会有整数规划?线性规划问题的最优解可能是分数或小数。整数规划是指变量的取值只能是整数的规划。这在实际问题中很常见,例如车间人数、设备台数、行驶次数,这些变量显然必须取整数解。整数规划并不一定是线性规划问题的变量取整限制,对于二次规划、非线性规划问题也有.

    2022年7月12日
    16
  • Android项目文件夹结构分析

    Android项目文件夹结构分析

    2021年11月13日
    140
  • TinyXML用法小结[通俗易懂]

    TinyXML用法小结[通俗易懂]TinyXML用法小结1.     介绍Tinyxml的官方网址:http://www.grinninglizard.com官方介绍文档:http://www.grinninglizard.com/tinyxmldocs/tutorial0.html在TinyXML中,根据XML的各种元素来定义了一些类:TiXmlBase:整个TinyXML模型的基类。TiXmlAttr…

    2022年5月7日
    87
  • 面试题—5种单例模式写法以及单线程和多线程下的区别

    面试题—5种单例模式写法以及单线程和多线程下的区别闲来无事看之前的博客,发现单例模式只会写2中。所以再重新开一篇博客,将目前自己所能理解的几种单例模式全部总结下。______________________________________________________________________________________________________________________1、懒汉式(最基本的) 单线程版写单例模式(饿汉式)的步骤: 1):必须在该类中,自己先创建出一个对象。 2):私有化自身的…

    2022年6月13日
    26
  • 最小设计流量怎么计算_动态限流算法

    最小设计流量怎么计算_动态限流算法给定一个包含 n 个点 m 条边的有向图,并给定每条边的容量和费用,边的容量非负。图中可能存在重边和自环,保证费用不会存在负环。求从 S 到 T 的最大流,以及在流量最大时的最小费用。输入格式第一行包含四个整数 n,m,S,T。接下来 m 行,每行三个整数 u,v,c,w,表示从点 u 到点 v 存在一条有向边,容量为 c,费用为 w。点的编号从 1 到 n。输出格式输出点 S 到点 T 的最大流和流量最大时的最小费用。如果从点 S 无法到达点 T 则输出 0 0。数据范围2≤n≤50

    2022年8月11日
    0
  • js 数组删除和添加数据「建议收藏」

    js 数组删除和添加数据「建议收藏」}//新增checkbox选中监听事件table.on(‘checkbox(LAY-team-add)’,function(obj){alert(obj.checked)varid=obj.data.id;if(obj.checked){addCheckbox.push(id);alert(addCheckbox)…

    2022年6月6日
    76

发表回复

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

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