Android-具有不同颜色和角度的背景色 [英] Android - Background color with different color and angles

查看:163
本文介绍了Android-具有不同颜色和角度的背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to figure out how to create this background in xml, couldn't find anything that helped me.

忽略孩子的圆圈图像,当然,我所说的是背景本身,有没有办法在xml?

Ignore the circle image of the kid and the text of course, I am talking about the background itself, is there a way to create something like that in xml?

在此先感谢您的帮助。
欢呼!

Thanks in advance for any help. cheers!

推荐答案

我猜您继续前进了,但是您可以使用矢量可绘制对象

I'm guessing you moved on, but you can do this using Vector Drawables.

以下内容不准确(直线并不完全笔直),但应该为您提供一个良好的开端:

The following is not accurate (the line is not completely straight), but should give you a good start:

新的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"
    />

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

You might need to add this to your layout as well:

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

注意:

  • Some more resources if someone will be interested: 1 2.
  • There's a preview for Vector Drawables in Android Studio.
  • Vector Drawables has been introduced in API 21, but should be supported in older APIs.

这篇关于Android-具有不同颜色和角度的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆