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 io 试题_Java IO流面试题

    java io 试题_Java IO流面试题字节流与字符流的不同是他们的处理方式,字节流是最基本的,采用ASCII编码。但是实际上很多数据是文本,所以提出字符流的概念,采用unicode编码两者之间通过inputStreamReader与outputStreamWriter来关联,实际上是通过byte[]与String来关联字节流输出:程序–>字节流–>文件字符流输出:程序–>字符流–>缓冲–>文件程序中所有…

    2022年4月25日
    28
  • push私库时遇到:Get https://192.168.0.180:5000/v1/_ping: http: server gave HTTP response to HTTPS client「建议收藏」

    push私库时遇到:Get https://192.168.0.180:5000/v1/_ping: http: server gave HTTP response to HTTPS client「建议收藏」解决方法:在”/etc/docker/“目录下,创建”daemon.json“文件。在文件中写入:{“insecure-registries”:[“192.168.0.180:5000”]}保存退出后,重启docker。问题解决

    2022年7月18日
    24
  • java过滤器的顺序(java过滤器指定过滤文件)

    过滤器的顺序由web.xml文件中&amp;lt;filter-mapping&amp;gt;的顺序决定,从上到下现有三个过滤器&amp;lt;filter&amp;gt;&amp;lt;filter-name&amp;gt;AFilter&amp;lt;/filter-name&amp;gt;&amp;lt;filter-class&amp;gt;com.jerry.filter.AF

    2022年4月12日
    153
  • internal server error原因及解决

    internal server error原因及解决常见的内部服务错误的原因有二,一是服务器资源紧张,二是文件权限错误。1.错误的原因一:服务器资源超载。服务器的资源超载:即同一时间内处理器有太多的进程需要处理的时候,会出现500错误。借助SSH,可

    2022年7月4日
    29
  • Hadoop与Spark等大数据框架介绍[通俗易懂]

    Hadoop与Spark等大数据框架介绍[通俗易懂]海量数据的存储问题很早就已经出现了,一些行业或者部门因为历史的积累,数据量也达到了一定的级别。很早以前,当一台电脑无法存储这么庞大的数据时,采用的解决方案是使用NFS(网络文件系统)将数据分开存储。但是这种方法无法充分利用多台计算机同时进行分析数据。一个实际的需求场景:日志分析日志分析是对日志中的每一个用户的流量进行汇总求和。对于一个日志文件,如果只有这么几行数据,我们一般会采用这…

    2022年4月28日
    43
  • xmind 使用教程[通俗易懂]

    1.这是刚刚打开xmind后的界面,在中央有一个中心主题,你可以把它替换成你自己的主题,比如图形推理。2、把光标定位到中心主题上,然后连续按3次Tab键,你会看到上面效果。tab键可以帮助你迅速的建立某个主题的子主题。3、下面你在连续按3次回车键,你就可以看到上面的效果,你可以通过回车键,建立同级主题。4、你自己在试一试,玩一玩者两个键吧!(tab键和enter回车键)5、如何改变主题的分布方式,你还要学习使用“右键”,选择一个主题,然后点击“右键”,你会发现有很多选择。6、选

    2022年4月9日
    363

发表回复

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

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