Android 创建可绘制的折弯线形状
我想在Android 创建可绘制的折弯线形状,android,android-layout,drawable,Android,Android Layout,Drawable,我想在TextView下面画一条弯曲的线,如下所示: 我认为背景绘图将是正确的,但我不知道如何实现这一点。有人有想法吗?shape.xml(将此文件保存在drawables中) 现在,如下设置TextView的背景属性:: <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/shape
TextView
下面画一条弯曲的线,如下所示:
我认为背景绘图将是正确的,但我不知道如何实现这一点。有人有想法吗?shape.xml(将此文件保存在drawables中)
现在,如下设置TextView的背景属性::
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape"
/>
shape.xml(将此文件保存在drawables中)
现在,如下设置TextView的背景属性::
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape"
/>
您可以使用
9-patch
图像创建背景,该图像来自使用您喜爱的图像编辑器创建的图像(这应该很容易做到),也可以创建xml可绘制图像。要在xml中创建这种类型的可绘制图形,可以使用一个ClipDrawable
,它将剪裁另一个Shape
drawable。因此,您将有:
background.xml(这将是TextView
的背景):
您可以通过使用ClipDrawable
的角半径、填充和级别来打磨可绘制图形的外观
我不知道您是否能够使用xml drawable获得准确的图像。您可以使用
9-patch
图像从您喜爱的图像编辑器创建的图像创建背景(这应该很容易做到),或者创建xml drawable。要在xml中创建这种类型的可绘制图形,可以使用一个ClipDrawable
,它将剪裁另一个Shape
drawable。因此,您将有:
background.xml(这将是TextView
的背景):
您可以通过使用ClipDrawable
的角半径、填充和级别来打磨可绘制图形的外观
我不知道您是否能够使用xml drawable获得准确的图像。您可以像这样创建一个9补丁drawable,并可以将其设置为TextView的背景,这实际上是最简单的方法,谢谢。你可以像这样创建一个9补丁drawble,并可以将其设置为TextView的背景,这实际上是最简单的方法,谢谢。
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="vertical"
android:drawable="@drawable/background_shape"
android:gravity="bottom" />
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp" />
<solid android:color="#ffffff" />
<padding
android:bottom="5dp"
android:left="7dp"
android:right="7dp" />
<stroke
android:width="2dp"
android:color="#000000" />
</shape>
ClipDrawable clip = (ClipDrawable) findViewById(R.id.textView1).getBackground();
clip.setLevel(5000);