【问题标题】:create drawable shape of right angled triangle创建直角三角形的可绘制形状
【发布时间】:2017-01-15 22:47:46
【问题描述】:

我正在尝试找出如何使用可绘制的 xml (<shape>) 创建一个如下所示的直角三角形(但用不带黑线的颜色填充):

我尝试从对角线将矩形减半的角度思考,但仍然......找不到如何实现它。

Android drawable xml 是否可行?

【问题讨论】:

  • 在 xml 中取一个 TextView 并在 java 文件中设置它的值,如下所示:textview.setText(Html.fromHtml("▶"));
  • 但我需要将它用作另一个视图的背景。使用 TextView 技巧不适用于该目的。我需要它作为可绘制资源。
  • 您可以使用这个stackoverflow.com/questions/25080396/drawing-triangle-in-xml并根据需要进行修改。
  • 请检查我的答案吗?

标签: android android-drawable android-shape android-shapedrawable


【解决方案1】:

给你:

创建您的 xml 文件

<?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_main10"
    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.Main10Activity">
    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/my_shape6"></LinearLayout>
</RelativeLayout>

在drawable文件夹中创建my_shape6.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">

    <path
        android:fillColor="#32c2b6"
        android:pathData="M0 20 L100 0 L100 20 Z"
        android:strokeColor="#9a1616" />

</vector>

结果

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-10
    • 2015-04-30
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多