一起Talk Android吧(第五百零六回:如何调整组件在约束布局中的角度)

news2024/9/23 23:33:05

文章目录

  • 背景介绍
  • 相关属性
  • 使用方法
  • 示例程序

各位看官们大家好,上一回中咱们说的例子是"如何调整组件在约束布局中的大小",这一回中咱们说的例子是"如何调整组件在约束布局中的角度"。闲话休提,言归正转, 让我们一起Talk Android吧!

背景介绍

我们在前面章回中介绍了如何调整组件在约束布局中的位置和大小,在实际项目中使用约束(constraintlayout)布局的时候需要调整组件在布局中的角度,进而调整组件的位置。这样的需求不是很多,但是也存在。比如使用花瓣的图片拼出一朵花,就需要按照角度来调整组件的位置。

相关属性

调整组件的角度需要使用组件的三个圆形类属性,详细如下:

app:layout_constraintCircle        //指定圆心组件
app:layout_constraintCircleRadius  //指定圆心半径
app:layout_constraintCircleAngle   //指定圆心角度
  • 圆心组件的属性值就是某个组件的id,圆心变化后其它的组件也会跟着变化;
  • 圆心半径的属性值就xxdp,它表示某个组件中心位置到圆心的距离,和数学中圆的半径含义相同;
  • 圆心角度的属性值是浮点数值,比如1.2.它表示当前组件与圆心的角度,12点钟方向为0度,沿着顺时针方向旋转,角度依次增大。直到360为止;

使用方法

我们通过具体的例子来说明这些属性的用法,示例:使用花瓣的图片拼出一朵花

  1. 选取一个图片组件当作花朵的圆心,
  2. 设置花瓣图片组件的三个圆形属性;
  3. 调整花瓣组件的半径和角度,使它们围绕圆心排列;

示例程序

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.ActivityConstrilayout">

    <ImageView
        android:id="@+id/id_circle_center"
        android:background="@drawable/ic_circle_in"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintVertical_bias="0.5"
        app:layout_constraintHorizontal_bias="0.5"

        app:layout_constraintWidth_default="percent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintWidth_percent="0.2"
        app:layout_constraintHeight_percent="0.1"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </ImageView>


    <ImageView
        android:background="@drawable/ic_circle_out"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintCircle="@id/id_circle_center"
        app:layout_constraintCircleRadius="65dp"
        app:layout_constraintCircleAngle="30.0"

        app:layout_constraintWidth_default="percent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintWidth_percent="0.2"
        app:layout_constraintHeight_percent="0.1"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </ImageView>


    <ImageView
        android:background="@drawable/ic_circle_out"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintCircle="@id/id_circle_center"
        app:layout_constraintCircleRadius="65dp"
        app:layout_constraintCircleAngle="90.0"

        app:layout_constraintWidth_default="percent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintWidth_percent="0.2"
        app:layout_constraintHeight_percent="0.1"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </ImageView>


    <ImageView
        android:background="@drawable/ic_circle_out"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintCircle="@id/id_circle_center"
        app:layout_constraintCircleRadius="65dp"
        app:layout_constraintCircleAngle="150.0"

        app:layout_constraintWidth_default="percent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintWidth_percent="0.2"
        app:layout_constraintHeight_percent="0.1"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </ImageView>


    <ImageView
        android:background="@drawable/ic_circle_out"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintCircle="@id/id_circle_center"
        app:layout_constraintCircleRadius="65dp"
        app:layout_constraintCircleAngle="210.0"

        app:layout_constraintWidth_default="percent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintWidth_percent="0.2"
        app:layout_constraintHeight_percent="0.1"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </ImageView>

    <ImageView
        android:background="@drawable/ic_circle_out"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintCircle="@id/id_circle_center"
        app:layout_constraintCircleRadius="65dp"
        app:layout_constraintCircleAngle="270.0"

        app:layout_constraintWidth_default="percent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintWidth_percent="0.2"
        app:layout_constraintHeight_percent="0.1"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </ImageView>

    <ImageView
        android:background="@drawable/ic_circle_out"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintCircle="@id/id_circle_center"
        app:layout_constraintCircleRadius="65dp"
        app:layout_constraintCircleAngle="330.0"

        app:layout_constraintWidth_default="percent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintWidth_percent="0.2"
        app:layout_constraintHeight_percent="0.1"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </ImageView>
</androidx.constraintlayout.widget.ConstraintLayout>

程序中创建了一个花朵,由七个ImageView组件构成,圆心使用一个ImageView组件实现,周围的花瓣使用六个ImageView组件实现;圆心的背景图片是橙色圆形,它没有使用圆形类的属性;花瓣的背景图片是黄色圆形,它们使用了圆形类属性,除了角度属性值不同外,其它属性都相同,下面是程序运行的效果图。
在这里插入图片描述

看官们,关于"如何调整组件在约束布局中的角度"的例子咱们就介绍到这里,欲知后面还有什么例子,且听下回分解!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/372723.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2、算法先导---思维能力与工具

题目 碎纸片的拼接复原(2013B) 内容 破碎文件的拼接在司法物证复原、历史文献修复以及军事情报获取等领域都有着重要的应用。传统上&#xff0c;拼接复原工作需由人工完成&#xff0c;准确率较高&#xff0c;但效率很低。特别是当碎片数量巨大&#xff0c;人工拼接很难在短时…

QT之OpenGL混合

QT之OpenGL混合1. 概述2. 实现2.1 丢弃片段2.1.1 Demo2.2 混合2.2.1 相关函数2.2.2 排序问题2.2.3 Demo1. 概述 OpenGL中&#xff0c;混合(Blending)通常是实现物体透明度(Transparency)的一种技术。 2. 实现 2.1 丢弃片段 在某些情况下&#xff0c;有些片段是只需要设置显…

尚医通(二十四)微信退款(取消预约功能)

目录一、取消预约1、需求描述2、开发取消预约接口一、取消预约 1、需求描述 取消订单分两种情况&#xff1a; &#xff08;1&#xff09;未支付取消订单&#xff0c;直接通知医院更新取消预约状态 &#xff08;2&#xff09;已支付取消订单&#xff0c;先退款给用户&#xff…

《程序是如何跑起来的》-----读书笔记篇

程序是如何跑起来的前言磁盘与内存的关系虚拟内存dll 文件运行环境从源文件到可执行文件前言 不得不说&#xff0c;在这个假期借助“微信阅读”读到了很多有意义的书。不仅是思想境界上的&#xff0c;还有专业方向的。这一次我是在周三还是周四的一个活动中淘到了这本书&#x…

Nginx的介绍、安装与常用命令

前言&#xff1a;传统结构上(如下图所示)我们只会部署一台服务器用来跑服务&#xff0c;在并发量小&#xff0c;用户访问少的情况下基本够用但随着用户访问的越来越多&#xff0c;并发量慢慢增多了&#xff0c;这时候一台服务器已经不能满足我们了&#xff0c;需要我们增加服务…

随机过程及应用

随机过程及应用一、概率论基础1. 三元体定义2. 随机变量及其分布1. 离散随机变量2. 连续型随机变量3. 常见的随机变量和分布1. 离散类2. 连续类4. 二维连续随机变量1. 二维离散2. 二维连续5. 随机变量函数的分布1. 离散&#xff08;可浅看&#xff09;2. 一维连续 r.v 函数分布…

JS学习第3天——Web APIs之DOM(什么是DOM,相关API【创建、增删改查、属性操作、事件操作API】)

目录一、Web APIs介绍1、API2、Web API二、DOM1、DOM树2、获取元素3、事件基础4、操作元素属性5、节点&#xff08;node&#xff09;操作三、DOM操作总结&#xff08;创建、增删改查、属性操作、事件操作API&#xff09;1、创建2、增3、删4、改5、查6、属性操作7、事件操作四、…

[QCustomPlot] QCPBar绘制柱状图并同时显示柱状图的值

前言 博主在使用 qcustomplot 绘制柱状图时&#xff0c;发现网络上的教程。大都忽略了一个重要的点就是。柱状图没有明显显示出当前的值。经过博主寻找后发现在 qcustomplot 论坛中已经有了对应的解决方案。所以记录一下。qcustomplot论坛 代码 void MainWindow::drawBars()…

【N32WB03x SDK使用指南】

【N32WB03x SDK使用指南】1. 简介1.1 产品简介1.2 主要资源1.3 典型应用2. SDK/开发固件文件目录结构2.1 doc2.2 firmware2.3 middleware2.4 utilities2.5 projects Projects3. 项目配置与烧录3.1 编译环境安装3.2 固件支持包安装3.3 编译环境配置3.4 编译与下载3.5 BLE工程目录…

Vue.js基础特性、生命周期及常用指令

目录 一、Vue构造选项 el根标签 data数据对象 methods定义方法 二、生命周期 三、常用指令 一、Vue构造选项 选项说明el唯一根标签&#xff0c;决定Vue实例会管理哪一个DOM节点dataVue实例对应的数据对象methods定义Vue实例的方法&#xff0c;可以在其他地方调用&#x…

慢SQL出现原因、优化、开启慢查询日志

文章目录慢SQL:出现原因&#xff1a;解决方式&#xff1a;开启慢查询日志&#xff1a;慢SQL: 出现原因&#xff1a; &#xff08;1&#xff09;数据库表索引设置不合理 &#xff08;2&#xff09;SQL语句有问题&#xff0c;需要优化 解决方式&#xff1a; &#xff08;1&am…

Java 抽象类和接口

文章目录一、抽象类1. 抽象类定义2. 抽象类成员特点二、接口1. 接口概述2. 接口成员特点3. 类和接口的关系4. 抽象类和接口的区别5. 接口案例三、形参和返回值一、抽象类 1. 抽象类定义 在 Java 中&#xff0c;一个没有方法体的方法应该定义为抽象方法&#xff0c;而类中如果…

现在转行做程序员的多吗?

曾经有一名程序员说&#xff0c;他在编写程序时&#xff0c;就像一个发明家在做实验&#xff1b;当他把程序编好可以运行时&#xff0c;他就已经是个发明家了。 程序员作为众多转行人员首选的职业&#xff0c;也是被大众熟知了。但我们需要知道的不仅是它作为一个职业的定义&a…

Spring超级全家桶,学完绝对是惊艳面试官的程度

前言Spring框架自2002年诞生以来一直备受开发者青睐&#xff0c;它包括SpringMVC、SpringBoot、Spring Cloud、Spring Cloud Dataflow等解决方案。有人亲切的称之为&#xff1a;Spring 全家桶。很多研发人员把spring看作心目中最好的java项目&#xff0c;没有之一。所以这是重点…

AtCoder Beginner Contest 290 G. Edge Elimination(思维题 枚举+贪心)

题目 T(T<100)组样例&#xff0c;每次给出一棵深度为d的k叉树&#xff0c; 其中&#xff0c;第i层深的节点个数为 保证k叉树的所有节点个数tot不超过1e18&#xff0c; 求在k叉树上构建一棵大小恰为x的连通块&#xff0c;所需要断开的最少的树边的条数(x<tot<1e18)…

VScode远程连接服务器-过程试图写入的管道不存在-could not establist connection to【已解决】

问题描述 使用服务器的过程中突然与服务器断连&#xff0c;报错如下&#xff1a;could not establist connection to [20:23:39.487] > ssh: connect to host 10.201.0.131 port 22: Connection timed out > [20:23:39.495] > 过程试图写入的管道不存在。 > [20…

hook与mixin

看完vue3就开始看vue3的源码&#xff0c;表示很懵~ 刚把rollup打包搞完&#xff0c;这不响应式就接着来了&#xff01;&#xff0c;还是写篇直接使用vue3的博客清清脑吧&#xff01; 什么是hook、mixin&#xff1f; mixin: Vue2中多个组件内存在重复JS业务逻辑&#xff0c;使…

JavaScript 闭包【自留】

闭包的概念理解 闭包的定义 ✅ 这里先来看一下闭包的定义&#xff0c;分成两个:在计算机科学中和在JavaScript中。 ✅ 在计算机科学中对闭包的定义(维基百科): 闭包(英语:Closure)&#xff0c;又称词法闭包(Lexical Closure)或函数闭包(function closures);是在支持头等函数…

QT之OpenGL模板测试

QT之OpenGL模板测试1. 概述2. 使用步骤及函数介绍3. Demo4. 参考1. 概述 当片段着色器处理完一个片段之后&#xff0c;模板测试(Stencil Test)会开始执行&#xff0c;和深度测试一样&#xff0c;它可能会丢弃片段。被保留下来的片段会进入深度测试。 一个模板缓冲中&#xff…

Web Spider Babel安装 Ast抽象语法 - 基本使用

文章目录一、资源地址二、遍历2.1 树结构遍历模式2.2 案例三、下载安装四、案例操作总结提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参考 一、资源地址 Ast反混淆语法在线网址&#xff1a;https://astexplorer.net Babel官方文档&#xff1a;https://ww…