I\'m new in Android development and I\'m trying to draw a line inside my yellow RelativeLayout from bottom left corner to top right corner.
I\'ve added a layer-list
You should use VectorDrawable path to draw line inside yellow RelativeLayout
from bottom left corner to top right corner. Your diagonal_line.xml
should be like (assume line color is blue #0000FF
and line width is 4
):
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="600"
android:viewportWidth="600" >
<path
android:name="diagonal_line"
android:strokeColor="#0000FF"
android:strokeWidth="4"
android:pathData="M600, 0 l-600, 600z" />
</vector>
(absolute dimensions not important, because vector will be rescaled for RelativeLayout
size). Your styles.xml
should include section
<style name="diagonalStyle">
<item name="android:background">@drawable/diagonal_line</item>
</style>
as you wrote, and in case you cannot use backgroundTint
in your {your_layout}.xml
file, you should set solid colored background (android:background="#FFDC7F"
) for your Relativelayout
and put "dummy" View
with diagonalStyle
(style="@style/diagonalStyle"
) over it. Something like that:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFDC7F"
tools:context="{YOUR_CONTEXT}">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/diagonalStyle" />
</RelativeLayout>
As result, you should give something like that:
More path tutorial here.