如何在Android中使用xml创建具有左右边框的向下箭头指示器
我想把我的观点做成这样的形状 有没有办法用xml做到这一点?如何在Android中使用xml创建具有左右边框的向下箭头指示器,android,xml,drawable,Android,Xml,Drawable,我想把我的观点做成这样的形状 有没有办法用xml做到这一点? 谢谢这是您的自定义绘图自定义形状向下箭头.xml: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Background --> <item> <shape and
谢谢这是您的自定义绘图
自定义形状向下箭头.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Background -->
<item>
<shape android:shape="rectangle">
<size
android:width="250dp"
android:height="20dp" />
<solid android:color="#cdcdcd" />
</shape>
</item>
<!-- Top-Left Line -->
<item
android:right="150dp"
android:bottom="18.7dp">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</item>
<!-- Top-Right Line -->
<item
android:left="150dp"
android:bottom="18.7dp">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</item>
<!-- Left-Diagonal Line -->
<item
android:right="25dp">
<rotate android:fromDegrees="36">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</rotate>
</item>
<!-- Right-Diagonal Line -->
<item
android:left="27dp">
<rotate android:fromDegrees="322">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</rotate>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="24dp"
android:gravity="center_horizontal">
<!-- Custom shape -->
<LinearLayout
android:id="@+id/layout_custom_shape"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:paddingTop="10dp"
android:background="#cdcdcd">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/custom_shape_down_arrow">
</LinearLayout>
</LinearLayout>
</LinearLayout>
使用:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Background -->
<item>
<shape android:shape="rectangle">
<size
android:width="250dp"
android:height="20dp" />
<solid android:color="#cdcdcd" />
</shape>
</item>
<!-- Top-Left Line -->
<item
android:right="150dp"
android:bottom="18.7dp">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</item>
<!-- Top-Right Line -->
<item
android:left="150dp"
android:bottom="18.7dp">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</item>
<!-- Left-Diagonal Line -->
<item
android:right="25dp">
<rotate android:fromDegrees="36">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</rotate>
</item>
<!-- Right-Diagonal Line -->
<item
android:left="27dp">
<rotate android:fromDegrees="322">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</rotate>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="24dp"
android:gravity="center_horizontal">
<!-- Custom shape -->
<LinearLayout
android:id="@+id/layout_custom_shape"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:paddingTop="10dp"
android:background="#cdcdcd">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/custom_shape_down_arrow">
</LinearLayout>
</LinearLayout>
</LinearLayout>
输出:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Background -->
<item>
<shape android:shape="rectangle">
<size
android:width="250dp"
android:height="20dp" />
<solid android:color="#cdcdcd" />
</shape>
</item>
<!-- Top-Left Line -->
<item
android:right="150dp"
android:bottom="18.7dp">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</item>
<!-- Top-Right Line -->
<item
android:left="150dp"
android:bottom="18.7dp">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</item>
<!-- Left-Diagonal Line -->
<item
android:right="25dp">
<rotate android:fromDegrees="36">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</rotate>
</item>
<!-- Right-Diagonal Line -->
<item
android:left="27dp">
<rotate android:fromDegrees="322">
<shape android:shape="line">
<stroke
android:color="#999999"
android:width="1dp" />
</shape>
</rotate>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="24dp"
android:gravity="center_horizontal">
<!-- Custom shape -->
<LinearLayout
android:id="@+id/layout_custom_shape"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:paddingTop="10dp"
android:background="#cdcdcd">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/custom_shape_down_arrow">
</LinearLayout>
</LinearLayout>
</LinearLayout>
希望这将有助于~您需要它的目的是什么?您可以尝试使用“九块补丁”图像背景。我想创建一个带有“视图寻呼机”的滑块,所选选项卡将指示另一个视图。向下箭头将指示启用的视图,该行的其余部分将分布在禁用的视图上,并希望使用xml创建。我认为此链接将帮助您:-谢谢,但我的情况完全不同。我只需要使用xml绘制一个带有上边框的向下箭头。然后我就可以完成剩下的任务了。很高兴知道这一点。如果我的答案似乎有用,那么请投赞成票。非常感谢。