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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 符号_王者荣耀2019名字特殊符号大全 最好看的特殊符号复制[通俗易懂]

    符号_王者荣耀2019名字特殊符号大全 最好看的特殊符号复制[通俗易懂][海峡网]大家玩王者荣耀的时候都会取一个特别的名字,如果再加上特殊符号的话,会让人更印象深刻,也比较容易交上朋友,那么2019年哪些特殊符号可以用在游戏中,一起来了解一下吧。【王者荣耀特殊符号推荐2019】1、爱心符号:დღ♡❣❤❥❦❧♥2、音符符号:♩♪♫♬♭♮♯3、文化符号:☠☤☥☦☧☨☩☪☫☬☮☭☯☸☽☾♕♚♛✙✚✛✜…

  • Hystrix:服务熔断

    Hystrix:服务熔断文章目录服务雪崩服务雪崩​多个微服务之间调用的时候,假设微服务A调用微服务B和微服务C,微服务B和微服务C又调用其他的微服务,这就是所谓的“扇出”,如果扇出的链路上某个微服务的调用响应时间过长,或者不可用,对微服务A的调用就会占用越来越多的系统资源,进而引起系统崩溃,所谓的“雪崩效应”。​对于高流量的应用来说,单一的后端依赖可能会导致所有服务器上的所有资源都在几十秒内饱和。比失败更糟糕的是,这些应用程序还可能导致服务之间的延迟增加,备份队列,线程和其他系统资源紧张,导致整个系统发生更多的级联故障,

    2022年10月21日
  • 什么软件可以更换手机ip地址「建议收藏」

    什么软件可以更换手机ip地址「建议收藏」这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML图表FLowchart流程图导出与导入导出导入欢迎使用Markdown编辑器你好!这是你第一次使用Markdown编辑器所展示的欢迎页。如果你想学习如何使用Mar

  • QVBoxLayout的使用

    QVBoxLayout的使用#include&lt;QApplication&gt;#include&lt;QPushButton&gt;#include&lt;QWidget&gt;#include&lt;QMenuBar&gt;#include&lt;QStatusBar&gt;#include&lt;QVBoxLayout&gt;#include&lt;QTextEdit&gt;#include&amp

  • PSCU选择Qlik支持其完善的服务交付战略「建议收藏」

    PSCU选择Qlik支持其完善的服务交付战略

  • 医疗器械进销存软件管理系统_简单仓库管理系统

    医疗器械进销存软件管理系统_简单仓库管理系统开发环境:Eclipse/MyEclipse、Tomcat8、Jdk1.8数据库:MySQL适用于:课程设计,毕业设计,学习等等系统介绍有偿

发表回复

您的电子邮箱地址不会被公开。

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