Android创建圆形布局
我试图创建一个循环布局,始终停留在屏幕上 为此,我创建了一个系统覆盖并添加了一个按钮 但是,现在我想把它弄圆 我可以使用4种不同的ImageView和textView,并将它们添加到FrameLayout中 我在某个地方读到过这样简单的东西可以通过XML实现 我该怎么做 我想实现这样的目标: 编辑 在遵循您的指导后,我实现了以下目标: 但我对过去的方式并不满意。 我所做的是创建2个形状(背景,圆形)并将它们添加到图层列表中 背景Android创建圆形布局,android,Android,我试图创建一个循环布局,始终停留在屏幕上 为此,我创建了一个系统覆盖并添加了一个按钮 但是,现在我想把它弄圆 我可以使用4种不同的ImageView和textView,并将它们添加到FrameLayout中 我在某个地方读到过这样简单的东西可以通过XML实现 我该怎么做 我想实现这样的目标: 编辑 在遵循您的指导后,我实现了以下目标: 但我对过去的方式并不满意。 我所做的是创建2个形状(背景,圆形)并将它们添加到图层列表中 背景 <?xml version="1.0" encoding
<?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>
放弃
<?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>
名单
然后,我使用了框架布局并添加了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>
然后通过服务使它们膨胀。但我对文本位置和我必须随机点击和尝试才能找到圆心的事实不满意
稍后,我将添加“收缩”以缩放视图,因此,我真的希望找到一种使文本自身与圆心对齐的方法。您需要创建一个可绘制的形状(在
res/drawable
文件夹中),如下所示:
邮政编码,而不仅仅是声明/要求。您尝试过什么?当您将Marcin建议的drawable设置为TextView的drawable时(您只需要一个TextView,其他什么都不需要),请确保在dp中为layout_width和layout_height指定相同的值。
<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>
<?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>