Android - Background color with different color and angles

百般思念 提交于 2019-12-23 10:39:04

问题


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

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!


回答1:


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:

New XML file:

<?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>

In your layout:

<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"

Notes:

  • 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.


来源:https://stackoverflow.com/questions/44430426/android-background-color-with-different-color-and-angles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!