2016-09-23 7 views
0

Die Art, wie ich in der Lage bin, dies zu tun, so weit eine XML-ziehbar zu erstellen:Wie kann ich meinem ImageView programmatisch einen abgerundeten Rahmen hinzufügen?

<?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> 

Und in meinem Layout 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> 

ist mein Problem, dass der Rahmen nicht der Fall ist Bedecken Sie die Ecken des Profilbildes, das dahinter gezeichnet werden kann, wodurch das tatsächliche Bild über den Rand hinaus blutet. Wie kann ich die Ecken abdecken? Ich wünschte wirklich, es gäbe jetzt eine CSS-ähnliche Eigenschaft für dieses Recht!

Antwort

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> 

Ihr Layout .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> 
Verwandte Themen