简体   繁体   English

使用 XML 自定义边的矩形

[英]Rectangle shape with custom side using XML

Is it possible to create a shape like this white rectangle?是否可以创建像这个白色矩形这样的形状? with that kind of side in the有这样的一面在此处输入图像描述 bottom?底部?

here it will help you在这里它会帮助你

XML file XML 档案

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#90000000"
tools:context=".DataGet">

<LinearLayout
    android:id="@+id/main"
    android:layout_marginTop="20dp"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

<ImageView
    android:id="@+id/iv1"
    android:layout_marginLeft="10dp"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>

<ImageView
    android:layout_toRightOf="@+id/iv1"
    android:id="@+id/iv2"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv2"
    android:id="@+id/iv3"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv3"
    android:id="@+id/iv4"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv4"
    android:id="@+id/iv5"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv5"
    android:id="@+id/iv6"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv6"
    android:id="@+id/iv7"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv7"
    android:id="@+id/iv8"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>

<ImageView
    android:id="@+id/iv9"
    android:layout_toRightOf="@+id/iv8"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>

<ImageView
    android:layout_toRightOf="@+id/iv9"
    android:id="@+id/iv10"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv10"
    android:id="@+id/iv11"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv11"
    android:id="@+id/iv12"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv12"
    android:id="@+id/iv13"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv13"
    android:id="@+id/iv14"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>
<ImageView
    android:layout_toRightOf="@+id/iv14"
    android:id="@+id/iv15"
    android:layout_below="@+id/main"
    android:layout_width="25dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>

<ImageView
    android:layout_toRightOf="@+id/iv15"
    android:id="@+id/iv16"
    android:layout_below="@+id/main"
    android:layout_width="20dp"
  android:layout_marginRight="10dp"
    android:background="@drawable/bg_flip_1"
    android:layout_height="25dp"/>

The Above code is simple to create a layout with a background with text View and have a linear layout on it to show Effect like card view.上面的代码很简单,可以创建一个带有文本视图的背景布局,并在其上有一个线性布局来显示类似卡片视图的效果。

You have to create a drawable name as "bg_flip_1" if you are coping above code else you can give your name and replace it with bg_flip_1 in XML file如果您要处理上述代码,则必须创建一个可绘制名称为“bg_flip_1”,否则您可以提供您的名称并将其替换为 XML 文件中的 bg_flip_1

Drawable will look like可绘制看起来像

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="100dp"
android:width="100dp"
android:viewportHeight="100"
android:viewportWidth="100" >
<group
    android:name="triableGroup">
    <path
        android:name="triangle"
        android:fillColor="#FFFFFF"
        android:pathData="M 0,20 L 0,0 L 100,0 L 100,20 L 54,55  l -1,0.6  l -1,0.4  l -1,0.2  l -1,0   l -1,-0  l -1,-0.2  l -1,-0.4  l -1,-0.6    L 46,55   L 0,20 -100,-100 Z" />
</group>

The Above code will Create a Triangle vector which we will use for making the below sharp shape上面的代码将创建一个三角形矢量,我们将使用它来制作下面的尖锐形状

here the triangle will look like this这里的三角形看起来像这样在此处输入图像描述

After implementing both will look like this实施后两者将如下所示

here is screenshot这是截图在此处输入图像描述

Perhaps the easiest way is to import an SVG of the rectangle (Resource manager > '+' > Import drawables), which Android Studio would convert to an XML drawable resource.也许最简单的方法是导入矩形的 SVG(资源管理器 >“+”> 导入可绘制对象),Android Studio 会将其转换为 XML 可绘制资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM