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


相关推荐

  • URL重写:RewriteCond指令与RewriteRule 指令格式

    URL重写:RewriteCond指令与RewriteRule 指令格式Rewirte主要的功能就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范。平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等。本文将针对mod_rewrite和URL匹配的技术细节,以及RewriteCond与RewriteRule指令格式进行探讨。Rew

    2022年5月3日
    36
  • 号称有效期至2017年的 ESET Nod32 “付费”许可证,只要能用一年就行了

    号称有效期至2017年的 ESET Nod32 “付费”许可证,只要能用一年就行了这两枚“付费”许可证流于网上已有一段时间。安装ESETNod32各版本(包括最新版ESS/EAV5)并用“二选一”激活后,ESETNod32界面显示:许可证有效期至2017-4-29;许可证类型—付费许可证。通过这段时间监测:病毒库更新正常,没有被封杀迹象。我将“付费”带引号是因为没人付费。至于能否真的坚持到2017年,依我之见大可不必纠结不必较真。安安生生无偿服务一年半载也就蛮不错了—…

    2022年6月18日
    28
  • vc怎么改变背景颜色_vc运行界面怎么设置颜色

    vc怎么改变背景颜色_vc运行界面怎么设置颜色最近眼睛发炎,特别怕亮色,看到vc的开发环境都太亮,于是想修改。1>在菜单”Tools”->”Options”的最后一页”Format”中选择“sourcewindow”,将前景色改为黑色,将背景色改为淡灰色。2>改变系统的窗口背景色.设置方法:桌面右击属性选择外观

    2022年8月12日
    48
  • sql: 分组后按照分组规则拼接字符串 — group by与 group_concat()

    sql: 分组后按照分组规则拼接字符串 — group by与 group_concat()Markdown编辑器写博客小技巧本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗Ctrl+B斜体Ctrl+I引…

    2022年5月23日
    268
  • HTML制作网页_手机制作html网页

    HTML制作网页_手机制作html网页一、步骤1、HTML1、新建文本文档2、改后缀名.html3、以记事本方式打开并编写代码4、保存,关闭后,直接双击打开网页

    2022年9月23日
    1
  • OllyDBG 激活成功教程入门教程「建议收藏」

    OllyDBG 激活成功教程入门教程「建议收藏」原链接:https://www.cnblogs.com/ECJTUACM-873284962/p/7653285.html一、OllyDBG的安装与配置OllyDBG版的发布版本是个ZIP压缩包,只要解压到一个目录下,运行OllyDBG.exe就可以了。汉化版的发布版本是个RAR压缩包,同样只需解压到一个目录下运行OllyDBG.exe即可:OllyDBG中各个窗口的功能如上图。简单解释一下各个窗口的功能,更详细的内容可以参考TT小组翻译的中文帮助:反汇编窗口:显示被调试

    2022年9月21日
    2

发表回复

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

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