【问题标题】:Android - Background color with different color and anglesAndroid - 具有不同颜色和角度的背景颜色
【发布时间】:2017-11-09 20:33:00
【问题描述】:

我正在试图弄清楚如何在 xml 中创建这个背景, 找不到任何对我有帮助的东西。

当然忽略小孩的圆形图片和文字,我说的是背景本身,有没有办法在xml中创建类似的东西?

提前感谢您的帮助。 干杯!

【问题讨论】:

  • 你也许可以使用 LayerList 来做到这一点,但使用 shape 似乎不支持三角形:/
  • 不能只用 xml 来完成。您将不得不在 java 类中使用 rotate() 方法。 This link 可能会有所帮助
  • 您可以在单个自定义视图中进行管理。在自定义视图中,在画布中绘制此背景。

标签: android android-view android-xml android-shape


【解决方案1】:

我猜你继续前进,但你可以使用 Vector Drawables 来做到这一点。

以下内容不准确(线不完全笔直),但应该给你一个好的开始:

新的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="100dp"
    android:width="100dp"
    android:viewportHeight="100"
    android:viewportWidth="100">

    <path
        android:name="dark_triangle"
        android:fillColor="@color/blue"
        android:pathData="M 0,100 L 0,80 60,70 100,80 100,100 z" />

    <path
        android:name="light_triangle"
        android:fillColor="@color/color_light_blue"
        android:pathData="M 60,70 L 100,65 100,80 z" />

</vector>

在你的布局中:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitCenter"
    app:srcCompat="@drawable/test"
    />

您可能还需要将此添加到您的布局中:

    xmlns:app="http://schemas.android.com/apk/res-auto"

注意事项:

【讨论】:

    猜你喜欢
    • 2015-07-30
    • 1970-01-01
    • 2023-03-03
    • 2011-04-13
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    • 2021-09-15
    相关资源
    最近更新 更多