0

I have a gradient view which animates from left to right. I have a XML that describes the circle inside, but the borders of XML are actually rectangular as you can see, how can I make the overflow hidden of the outside of the XML. It looks like that only the background is a circle but not the the shape itself ,I thought that the solution is by using PorterDuff.Mode but it doesn't help.

this is my circle.xml file:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <stroke
        android:width="2dp"
        android:color="@android:color/white" />

    <corners android:radius="7.5dp" />
    <size android:width="327dp" android:height="211.5dp" />

</shape> 

And in my layout i use it like this :

  <RelativeLayout
        android:id="@+id/white_rectangle"
        android:layout_width="327dp"
        android:layout_height="211.5dp"
        android:layout_gravity="center"
        android:clipChildren="true"
        android:adjustViewBounds="true"
        android:background="@drawable/circle"
        >

        <View
            android:id="@+id/scanner"
            android:layout_width="123.5dp"
            android:layout_height="211.5dp"
            android:layout_gravity="center"
            android:background="@drawable/scanner"
            android:visibility="gone" />

    </RelativeLayout>

scanner

i don't want the scanner to go outside the borders

Maxim Toyberman
  • 1,906
  • 1
  • 20
  • 35

3 Answers3

0

You need to set square dimensions for it to appear as a circle.

Your width is larger than your height. Try this

  <RelativeLayout
        android:id="@+id/white_rectangle"
        android:layout_width="211.5dp"
        android:layout_height="211.5dp"
        android:layout_gravity="center"
        android:clipChildren="true"
        android:adjustViewBounds="true"
        android:background="@drawable/circle"
        >

        <View
            android:id="@+id/scanner"
            android:layout_width="123.5dp"
            android:layout_height="123.5dp"
            android:layout_gravity="center"
            android:background="@drawable/scanner"
            android:visibility="gone" />

    </RelativeLayout>
Brandon Stillitano
  • 1,304
  • 8
  • 27
0

The solution for me was to use CardView and give it cardCornerRadius.

found it here How to make a view in android with rounded corners

Maxim Toyberman
  • 1,906
  • 1
  • 20
  • 35
-1

try this library. Use same height and width for view

https://github.com/hdodenhof/CircleImageView

Brandon Stillitano
  • 1,304
  • 8
  • 27
Rajkumar Sharma
  • 554
  • 1
  • 4
  • 9