Android创建循环布局

时间:2014-01-08 11:51:58

标签: android

我正在尝试创建一个始终保持在屏幕上的圆形布局。

为此,我创建了一个系统覆盖并添加了一个按钮。

但是,现在我想完成它。

我可以使用4个不同的ImageView和textView,并将它们都添加到FrameLayout。

我在某处读过像这样简单的事情可以用XML制作。

我该怎么做?

我想实现这样的目标:

enter image description here

修改

按照指南后,我能够做到这一点: enter image description here

但我对我使用的方式并不满意。 我所做的是创建2个形状(背景,forground)并将它们添加到图层列表中。

背景

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >

<solid android:color="#50000000" />

</shape>

FORGROUND

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >

<solid android:color="#99009900" />

</shape>

LIST

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:drawable="@drawable/circleback">
</item>
<item
    android:bottom="5dp"
    android:drawable="@drawable/circlefront"
    android:left="5dp"
    android:right="5dp"
    android:top="5dp">
</item>

</layer-list>

然后,我使用了framelayout并添加了2个textview。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:background="@drawable/circle" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="33dp"
    android:text="@string/data_left"
    android:layout_marginTop="8dp"
    android:textColor="#fff"
    android:textSize="30sp"
    android:typeface="sans" 
    android:textStyle="bold"/>


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="25dp"
    android:text="@string/band"
    android:layout_marginTop="40dp"
    android:textColor="#fff"
    android:textSize="20sp"/>
</FrameLayout>

然后通过服务夸大他们。但我对文本位置以及我必须随机点击并试用以找到圆心的事实并不满意。

我稍后会添加缩放来缩放以查看,所以我真的想找到一种文本将自身对齐到圆心的方式。

1 个答案:

答案 0 :(得分:0)

您需要创建一个可绘制的形状(在res/drawable文件夹中),如:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" 
   <solid android:color="#ff00ff00 />
</shape>

请参阅文档:https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape