Issue
I have XML of the light brown circle and I want to place it as background on the top left corner as shown in the pic
Can anyone guide me on how I can do it? I need to show it on multiple screens on different sides. Any hint will be much appreciated
here is the XML of circle
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/light_brown"/>
<!-- Set the same value for both width and height to get a circular shape -->
<size android:width="550sp" android:height="550sp"/>
</shape>
</item>
</selector>
Solution
You can wrap your ImageView
in ConstraintLayout
and add constraints of:
app:layout_constraintDimensionRatio="1:1"
: Making width and height equal (or as proportional as you want)app:layout_constraintWidth_percent="0.5"
: a percentage you need of the Width relative to the parentConstraintLayout
, here I see it half
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/profile_image_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/quarter"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
You can use the following quarter of a circle drawable instead of a full circle
drawable\quarter.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size
android:width="15dp"
android:height="15dp" />
<solid android:color="@color/light_brown" />
<corners android:bottomRightRadius="250dp" />
</shape>
</item>
</layer-list>
Result:
Answered By - Zain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.