Issue
I am trying a draw a red rectangle covering 40% of the width of a white rectangle in android.
xml file is like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@android:id/background"
android:gravity="center_vertical|fill_horizontal">
<shape android:shape="rectangle">
<size android:height="10dp" />
<solid android:color="@color/colorWhite" />
</shape>
</item>
<item
android:id="@+id/level_to_next"
android:gravity="center_vertical|left">
<shape android:shape="rectangle">
<size android:height="10dp"
android:width="0dp" />
<solid android:color="@color/colorRed_80" />
</shape>
</item>
</layer-list>
However, setting width to item with id level_to_next has no effect in xml file. Red rectangle covers the whole width of white rectangle.
How can I control the width of the red rectangle?
Solution
Try setting the height and width of both rectangles like the following. I changed the sizes to better see the rectangles on the screen, but you can change them to something else.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@android:id/background"
android:gravity="center_vertical|fill_horizontal">
<shape android:shape="rectangle">
<size android:height="100dp"
android:width="100dp" />
<solid android:color="@color/colorWhite" />
</shape>
</item>
<item
android:id="@+id/level_to_next"
android:gravity="center_vertical|left">
<shape android:shape="rectangle">
<size android:height="40dp"
android:width="40dp" />
<solid android:color="@color/colorRed_80" />
</shape>
</item>
</layer-list>
Answered By - Cheticamp
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.