2016-10-19 64 views
0

我想要添加一個帶圓角的圖像到我的imageView,但它不會出現圓角。Android Image圓形頂部

我shape_round_top.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
<solid android:color="@android:color/darker_gray"/> 
<corners android:topRightRadius="10dp" 
    android:bottomRightRadius="0.1dp" 
    android:topLeftRadius="10dp" 
    android:bottomLeftRadius="0.1dp"/> 
</shape> 

我layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="200dp" 
android:layout_height="250dp" 
android:background="@drawable/grid_bg"> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="200dp"> 

    <ImageView 
     android:layout_width="200dp" 
     android:layout_height="100dp" 
     android:scaleType="fitXY" 
     android:id="@+id/image1" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_marginTop="5dp" 
     android:background="@drawable/shape_round_top" 
     android:layout_marginLeft="3dp" 
     android:layout_marginRight="3dp" /> 
     </RelativeLayout> 

     </LinearLayout> 

設置我的圖像編程

 int id; 
     id = context.getResources().getIdentifier("imagename", "drawable", context.getPackageName()); 
     image.setImageResource(id); 

回答

0

你鍵入正確繪製名android:background="@drawable/shape_round_top"android:background="@drawable/shape"? 除此之外,一切看起來都很好

+0

是shape.xml是shape_rounded_top,這是正確的。這是我在這個問題上的錯。我找不到錯誤。 – Fesco

+0

我在我的項目中測試了你的shape_round_top.xml和你的imageView,對我有效@Fesco – Chenmin

+0

那麼我的問題是我的圖像會變大? – Fesco