android 布局圆形_Android约束布局–圆形定位

本文介绍了如何使用Android约束布局的圆形定位特性创建自定义时钟UI。通过设置角度和半径,可以实现视图的循环定位。教程详细讲解了关键属性的定义,并提供了实现代码示例,包括XML布局文件和Java代码,展示了一个以ImageView为中心,TextViews围绕其按小时分布的时钟界面,还涉及了防止内存泄漏的处理方法。
摘要由CSDN通过智能技术生成

android 布局圆形

In this tutorial, we’ll be discussing a cool attribute present in Constraint Layout, namely circular positioning. We’ll be developing a custom clock UI in our Android Application using the same.

在本教程中,我们将讨论约束布局中存在的一个很酷的属性,即圆形定位。 我们将使用相同的方法在Android应用程序中开发自定义时钟UI。

Android约束布局 (Android Constraint Layout)

We’ve discussed Constraint Layout in this tutorial.

我们已经在本教程中讨论了约束布局。

It’s a great layout and provides lots of points to set views relative to one another.

这是一个很棒的布局,并提供了许多要点来设置相对于彼此的视图。

With the introduction of ConstraintLayout 1.1, we can now set positions based on angles and radius too. This is termed as circular positioning.

通过引入ConstraintLayout 1.1,我们现在也可以基于角度和半径设置位置。 这称为圆形定位。

循环定位 (Circular Postioning)

A picture is worth a thousands of words:

一幅图片值得一千个单词:

android constraint layout circular positioning

From Google Docs

来自Google文档

Circular Positioning consists of the following three attributes that need to be defined in the ConstraintLayout child views:

循环定位包含以下三个属性,这些属性需要在ConstraintLayout子视图中定义:

  • layout_constraintCircle : This would be defined in the View B. It would be set to the id of A.

    layout_constraintCircle :这将在视图B中定义。它将设置为A的ID。
  • layout_constraintCircleRadius : The distance between the center of the two views.

    layout_constraintCircleRadius :两个视图的中心之间的距离。
  • layout_constraintCircleAngle : The angle defines the circular position of B with respect to A. This is set in degrees( 0 to 360). An angle of 0 means the view B is vertically above A.

    layout_constraintCircleAngle :角度定义B相对于A的圆形位置。以度(0到360)设置。 角度为0表示视图B垂直于A。

We can create a complete circle with views positioned at different angles.

我们可以创建一个完整的圆,并以不同角度放置视图。

In the following section, we’ll create a custom clock in which TextViews would be circularly positioned around an ImageView.

在下一节中,我们将创建一个自定义时钟,其中TextViews将围绕ImageView循环放置。

Each t

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值