How add corner radius for imageview

How I add corner radius for imageview, if add shape with xml my shape in bacground and image is full no have corner

Posts

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    There are lots of ways to do this. You mentioned that you were using XML, so here is one trick/hack along that lines. It's not the most elegant, but it's pretty simple. It involves using two ImageViews in a FrameLayout, one ImageView holds what you want to display, the other holds a "frame" with rounded corners:

    1. Create a file called rounded_frame.xml and place it in your drawables folder:

      <?xml version="1.0" encoding="utf-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
      <solid android:color="#00ffffff" />
          <padding android:left="6dp"
                      android:top="6dp"
                          android:right="6dp"
                          android:bottom="6dp" />
           <corners android:radius="12dp" />
           <stroke android:width="6dp" android:color="#ffffffff" />
      </shape> 
      
    2. Next add a FrameLayout, which will contain two images views, one with your picture and another with a frame to rounde the corners.

       <FrameLayout 
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
      
              <ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:padding="6dp"
                  android:src="@drawable/sleepy_doc"/>
      
              <ImageView 
                   android:src="@drawable/rounded_frame"
                   android:layout_width="match_parent"
                   android:layout_height="match_parent" />
          </FrameLayout>
      

    This isn't the only way to achieve this effect, but it's a pretty easy way. I'll see if I can whip up a sample project later today for you.

  • IbrahimSusicIbrahimSusic BAMember

    @TomOpgenorth ty, can I android:color="#ffffffff" in stroke set gradient and how ? My question and code https://forums.xamarin.com/discussion/40386/how-add-gradient-to-stroke#latest

  • Ram.ShRam.Sh ILUniversity ✭✭

    @TomOpgenorth - when trying your sample get an error:

    No resource found that matches the given name (at 'src' with value '@drawable/rounded_frame')

    The rounded_frame.xml file is hosted inside the drawable folder and if I type in my code Resource.Drawable.rounded_frame the Intellisense recognize and completes it.

    Any thoughts what I'm missing here?

    Cheers,
    R.

Sign In or Register to comment.