使用XML的箭头矩形形状

时间:2023-02-09 23:50:48

How to implement this shape of Departments header using shape and xml without 9-patch ?

如何在没有9-patch的情况下使用shape和xml实现这种形状的Departments头?

I mean rectangle with arrow on the left.

我的意思是左边带箭头的矩形。

使用XML的箭头矩形形状

My code snippet:

我的代码片段:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="1px"
        android:left="@dimen/edittext_border"
        android:right="@dimen/edittext_border"
        android:top="@dimen/edittext_border">
        <shape android:shape="rectangle">
            <stroke
                android:width="@dimen/edittext_border_width"
                android:color="@color/menu_divider" />

            <solid android:color="@color/background" />
            <corners android:radius="4dp" />


        </shape>
    </item>
</layer-list>

1 个解决方案

#1


7  

if you are looking for someting like this, try the following code..

如果您正在寻找这样的东西,请尝试以下代码..

使用XML的箭头矩形形状

  1. Make a xml arrow_shape in your drawable folder.

    在drawable文件夹中创建一个xml arrow_shape。

     <?xml version="1.0" encoding="utf-8"?>
     <layer-list xmlns:android="http://schemas.android.com/apk/res/android">   
     <item>
     <rotate android:fromDegrees="45" android:toDegrees="45"  
       android:pivotX="-40%" android:pivotY="87%" >
        <shape android:shape="rectangle" >
            <stroke android:color="#c6802a" android:width="10dp"/>
            <solid android:color="#c6802a" />
        </shape>
    </rotate>
    </item>
    </layer-list>
    
  2. Make a xml rectangle_shape in your drawable folder.

    在drawable文件夹中创建一个xml rectangle_shape。

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
     <shape android:shape="rectangle">
        <solid android:color="#B2E3FA" />
     </shape>
    </item>
    
  3. In your main xml file

    在您的主xml文件中

    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.stpl.myapplication.MainActivity">
    
    <RelativeLayout
        android:id="@+id/arrow"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/arrow_shape"
        android:rotation="270" />
    
      <RelativeLayout
       android:id="@+id/rectangle"
       android:layout_width="150dp"
       android:layout_height="50dp"
       android:background="@drawable/rectangle_shape"
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:android="http://schemas.android.com/tools" />
    
    </LinearLayout>
    

#1


7  

if you are looking for someting like this, try the following code..

如果您正在寻找这样的东西,请尝试以下代码..

使用XML的箭头矩形形状

  1. Make a xml arrow_shape in your drawable folder.

    在drawable文件夹中创建一个xml arrow_shape。

     <?xml version="1.0" encoding="utf-8"?>
     <layer-list xmlns:android="http://schemas.android.com/apk/res/android">   
     <item>
     <rotate android:fromDegrees="45" android:toDegrees="45"  
       android:pivotX="-40%" android:pivotY="87%" >
        <shape android:shape="rectangle" >
            <stroke android:color="#c6802a" android:width="10dp"/>
            <solid android:color="#c6802a" />
        </shape>
    </rotate>
    </item>
    </layer-list>
    
  2. Make a xml rectangle_shape in your drawable folder.

    在drawable文件夹中创建一个xml rectangle_shape。

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
     <shape android:shape="rectangle">
        <solid android:color="#B2E3FA" />
     </shape>
    </item>
    
  3. In your main xml file

    在您的主xml文件中

    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.stpl.myapplication.MainActivity">
    
    <RelativeLayout
        android:id="@+id/arrow"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/arrow_shape"
        android:rotation="270" />
    
      <RelativeLayout
       android:id="@+id/rectangle"
       android:layout_width="150dp"
       android:layout_height="50dp"
       android:background="@drawable/rectangle_shape"
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:android="http://schemas.android.com/tools" />
    
    </LinearLayout>