答案 0 :(得分:1)
drawable_line.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="@android:color/black"
android:centerColor="@android:color/white
android:endColor= "@android:color/black"
android:angle="360"
/>
</shape>
将其作为view
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:background="@drawable/drawable_line" />
答案 1 :(得分:0)
在activity_main中添加这些:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:gravity="center"
android:background="@android:color/black"
android:layout_width="match_parent"
android:layout_height="80dp">
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/line" />
</LinearLayout>
</LinearLayout>
并创建可绘制的res文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="360"
android:centerColor="@android:color/white"
android:endColor="@android:color/black"
android:startColor="@android:color/black" />
</shape>