如何在Android中创建Circular Reel视图?

时间:2018-06-05 18:11:27

标签: android ios android-layout ios-autolayout

enter image description here

如何在Android中创建这样的视图?我使用可绘制的圆形

创建了圆形主框架图像
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="#000"/> <!-- this one is ths color of the  Rounded Button -->
    <corners
        android:bottomRightRadius="100dp"
        android:bottomLeftRadius="100dp"
        android:topLeftRadius="100dp"
        android:topRightRadius="100dp"/>
</shape>

如何将内部图像放在这个圆形框架中?

1 个答案:

答案 0 :(得分:3)

enter image description here

使用圆形卷轴图像作为遮罩:剪切图像插槽,使图像所在的alpha为零。您将在图片顶部最后绘制此图像。

每个插槽中的每个图像都需要旋转并转换为插槽位置。首先旋转图像(关于图像的中心),然后将图像转换为图像的插槽。

您不需要动态执行此操作,因为插槽已全部修复。这意味着您使用常规旧笔和纸计算图像变换,然后手动将每个变换构建到布局标记中。一些有用的公式来自极坐标系(r,theta)和转换为笛卡尔坐标系(x,y)。我在图片中的所有数学都是度数,但你最好用弧度工作。

R是圆的半径,即从卷轴中心到视图槽中心线的距离。

如果我是你(如果你想动态更改图像)那么我会找到如何为每个变换指定一个空槽并事后添加图像。

练习将单个图像排成一行,然后对其余的插槽进行数学处理。