2016-09-23 4 views
0

Пути я был в состоянии сделать это до сих пор является созданием XML вытяжки:Как я могу программно добавить округленную границу к моему ImageView?

<?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="0dp" 
     android:top="0dp" 
     android:right="0dp" 
     android:bottom="0dp" /> 
    <corners android:radius="12dp" /> 
    <stroke android:width="3dp" android:color="#ffffffff" /> 
</shape> 

И в моем макете XML:

 <FrameLayout 
      android:layout_width="64dp" 
      android:layout_height="64dp" 
      android:layout_gravity="top|center_horizontal"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/profilePicture" 
       android:scaleType="fitXY" 
       android:clickable="true" 
       android:contentDescription="@string/content_desc_profile_picture" /> 

      <ImageView 
       android:src="@drawable/frame" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:contentDescription="@string/content_desc_default_profile_picture" /> 

     </FrameLayout> 

Моя проблема в том, что рама не покройте углы профиля, вытягивающегося за ним, заставив фактическое изображение вылететь через границу. Как я могу покрыть углы? На самом деле, желая, чтобы на данный момент существовало свойство CSS-подобного права!

ответ

1

shape.xml

<?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
     <solid android:color="#000000" /> 
     <corners android:radius="2dp" /> 
    </shape> 

Ваш макет .xml

<FrameLayout 
     android:layout_width="64dp" 
     android:layout_height="64dp" 
     android:layout_gravity="top|center_horizontal" xmlns:android="http://schemas.android.com/apk/res/android"> 



    <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/shape" 
    /> 
    <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/profilePicture" 
      android:scaleType="fitXY" 
      android:clickable="true" 
      android:layout_margin="5dp" 
      android:src="@drawable/your_image" 
      android:background="@drawable/shape" /> 

</FrameLayout> 
Смежные вопросы