Отрисовываемая стрелка XML в фоновом режиме не работает - PullRequest
0 голосов
/ 30 августа 2018

Я сделал стрелку в drawable xml, которую я хочу использовать в качестве textview фона. Но результат не соответствует моим ожиданиям. Я хочу, чтобы первая стрелка показалась на данной картинке. Как это сделать? Можно ли это сделать с drawable xml.

Выход: enter image description here

Ожидаемый результат: enter image description here

Мой xml-код для рисования:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Colored rectangle-->
    <item>
        <shape android:shape="rectangle">
            <size
                android:width="@android:dimen/thumbnail_height"
                android:height="40dp" />
            <solid android:color="#5EB888" />
            <corners android:radius="0dp"/>
        </shape>
    </item>

    <!-- This rectangle for the top arrow edge -->
    <!-- Its color should be the same as the layout's background -->
    <item
        android:top="-50dp"
        android:bottom="65dp"
        android:right="-30dp">
        <rotate
            android:fromDegrees="45">
            <shape android:shape="rectangle">
                <solid android:color="#ffffff" />
            </shape>
        </rotate>
    </item>

    <!-- This rectangle for the lower arrow edge -->
    <!-- Its color should be the same as the layout's background -->
    <item
        android:top="65dp"
        android:bottom="-50dp"
        android:right="-30dp">
        <rotate
            android:fromDegrees="-45">
            <shape android:shape="rectangle">
                <solid android:color="#ffffff" />
            </shape>
        </rotate>
    </item>
</layer-list>

код компоновки адаптера:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center"
    android:layout_marginLeft="10dp"
    android:background="#123"
    android:layout_marginBottom="5dp"
    >

    <TextView
        android:id="@+id/wifiNameShowTvId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="10dp"
        android:textSize="20sp"
        android:background="@drawable/custom_shape_ssid"
        android:textColor="#f9f9f9"
        android:text="dkjfsjkfhskjdfhksjdfh "

        />

</LinearLayout>
* * Тысяча двадцать-один.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.

1 Ответ

0 голосов
/ 30 августа 2018

попробуйте

<item>
    <shape android:shape="rectangle">
        <solid android:color="#FAD55C" />
    </shape>
</item>

<item
    android:left="30dp"
    android:right="-30dp">
    <rotate android:fromDegrees="-40">
        <shape android:shape="rectangle">
            <solid android:color="#fff" />
        </shape>
    </rotate>
</item>

<item
    android:left="30dp"
    android:right="-30dp">
    <rotate android:fromDegrees="40">
        <shape android:shape="rectangle">
            <solid android:color="#fff" />
        </shape>
    </rotate>
</item>

и поместите это на свой макет фона вот так

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/demo_shape"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:paddingBottom="5dp"
            android:paddingLeft="18dp"
            android:paddingTop="5dp"
            android:text="Hey"
            android:textSize="20sp" />

    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/demo_shape"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:paddingBottom="5dp"
            android:paddingLeft="18dp"
            android:paddingTop="5dp"
            android:text="Hey"
            android:textSize="20sp" />

    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/demo_shape"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:paddingBottom="5dp"
            android:paddingLeft="18dp"
            android:paddingTop="5dp"
            android:text="Hey"
            android:textSize="20sp" />

    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/demo_shape"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:paddingBottom="5dp"
            android:paddingLeft="18dp"
            android:paddingTop="5dp"
            android:text="Hey"
            android:textSize="20sp" />

    </LinearLayout>

</LinearLayout>

OUTPUT

enter image description here

...