2017-06-03 218 views
-1

我想为这个视图创建一个形状。如何使用xml在Android中创建带有左右边框的向下箭头指示器

enter image description here

有没有办法做到这一点使用XML? 感谢

+0

你需要什么目的? –

+0

您可以尝试使用9个补丁的图像背景。 –

+0

我想创建一个带查看寻呼机的滑块,选定的选项卡将指示另一个视图。向下箭头将指示已启用的视图,并且该行的其余部分将遍布禁用的视图并希望使用xml进行创建。 – user2817947

回答

2

这里是你的自定义绘制custom_shape_down_arrow.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> 

OUTPUT:

enter image description here

希望这会有所帮助〜

+0

它的工作原理。谢谢 – user2817947

+0

很高兴知道。如果我的回答看起来有用,那么请将它投票。谢谢... – FAT

相关问题