I am trying to create a TextView whose background is a half circle. I create a oval using a ShapeDrawable. I tried to create a semicircle by using ScaleDrawable to double the size vertical size of the oval and clip it. However, the ScaleDrawable has no effect. Why not? What is the best way to draw a semicircle in the background of a View?
res/layout/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/main_view"
android:background="@drawable/semicircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:gravity="center_horizontal"
/>
</RelativeLayout>
res/drawable/semicircle.xml
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/circle"
android:scaleGravity="top|clip_vertical"
android:scaleHeight="200%"
android:scaleWidth="100%" >
</scale>
res/drawable/circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
<solid
android:color="#444" />
</shape>
src/.../MainActivity.java
//...
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
findViewById(R.id.main_view).getBackground().setLevel(10000);
}
//...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…