【问题标题】:How to create this shape in Android如何在 Android 中创建此形状
【发布时间】:2016-08-18 21:28:11
【问题描述】:

我想创建像这张图片这样的形状:

但我不想使用9 pach png 图像,我想在可绘制文件夹中创建这个形状。
我怎样才能创建这个? 任何帮助都将不胜感激!谢谢

【问题讨论】:

  • 三角形至少需要一个 9 补丁。否则,它是 2 个矩形
  • @cricket_007,是的,它是 2 个矩形,但我不想使用 9 个补丁图像。我想用形状创建这个
  • 这篇文章或许值得一看:stackoverflow.com/questions/2517589/…
  • @cricket_007,谢谢你,我用可绘制和 XML 创建了这个。创建这个之后,我在这个主题中发送代码。感谢您的帮助

标签: android android-shape


【解决方案1】:

创建您的布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main7"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ul_ts.emvsdktester.drawabletraining.Main7Activity">


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/my_shape4"></LinearLayout>

</RelativeLayout>

在您的可绘制文件中创建 my_shape4.xml

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="100dp"
    android:height="100dp"
    android:viewportHeight="100"
    android:viewportWidth="100">
    <group>
        <path
            android:pathData="M0 20 L50 20 L60 0 L100 0"
            android:strokeColor="#000000"
            android:strokeWidth="4" />
        <path
            android:fillColor="#42ce3b"
            android:pathData="M100 0 L100 50 L0 50 L0 20 L50 20 L60 2 L100 2"
            android:strokeWidth="0" />
    </group>
</vector>

结果

【讨论】:

  • 你能解释一下,你是如何创建 my_shape4.xml
  • @UmarAta 在您的可绘制文件夹中创建一个名为 my_shape4.xml 的示例文件,并复制我在答案中发布的副本。容易!!
  • 这不是我问的,我只是想问一下,你是如何为这个形状编写可绘制的矢量的,有没有教程或链接用于 decumentation?
  • @UmarAta 你可以在this link中准备更多关于向量的信息
猜你喜欢
  • 1970-01-01
  • 2017-07-27
  • 2018-08-29
  • 1970-01-01
  • 2021-09-02
  • 1970-01-01
  • 2013-11-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多