2016-06-15 4 views
0

私は、BaseAdapterを使用してカスタムレイアウトでGridViewをレンダリングしています。私のビューには、ImageViewとImageViewの下にTextViewがあります。私は丸みのあるコーナーボーダーを黒色で設定したいと考えています。Xamarin色付きのAndroidの角丸ボーダーImageView

私はコミュニティの回答からいくつかの提案を試みました。

  1. ドロアブルを丸めて作成し、ImageViewの背景として設定します。
  2. フレームとして機能するもう1つのダミーImageViewを使ってImageViewをFrameLayoutにラップし、枠線の描画可能領域をバックグラウンドとして設定します。
  3. RoundedBitmapをRoundedBitmapDrawableFactoryを使用して作成し、border drawableを背景として設定します。

上記のすべてのケースで、私は得ると思われます。 イメージの境界線はイメージと重複しています。

問題は、境界線と丸みを帯びたビットマップのコーナーが完全に一致していないことです。オプション コードについて more details, see comments. Further details

:私は、コードを使用して丸みを帯びたビットマップを作成した場合、それは深刻なメモリの問題を持っている

see here複数の画面サイズをサポートするためにそれを行う方法を確認していないとの密度:

internal void SetImageWithRoundCorners(int imageResID, Context context) 
{ 
    Resources res = context.Resources; 
    Bitmap src = BitmapFactory.DecodeResource(res, imageResID); 
    RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.Create(res, src); 
    dr.CornerRadius = 50.0f; 
    ImgTopicIcon.SetImageDrawable(dr); 
} 

round_border_corner.xml

<!-- language: lang-xml --> 
<?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="2dp" 
     android:top="2dp" 
     android:right="2dp" 
     android:bottom="2dp" /> 
    <corners android:radius="@dimen/GVImgRoundCornerRad" /> 
    <stroke android:width="2dp" android:color="#ff000000" /> 
</shape> 

Grid_Custom_Item.xml

<!-- language: lang-xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:minHeight="48dp" 
    android:gravity="center" 
    android:orientation="vertical"> 
    <FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/ImgCategoryIcon" /> 
     <ImageView 
      android:src="@drawable/round_corner_border" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </FrameLayout> 
    <TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textColor="@android:color/black" 
    android:id="@+id/TxtCategoryName" 
    android:gravity="center" /> 
</LinearLayout> 

期待される結果: http://screencast.com/t/6hd8moeTgqAQ

出力: http://screencast.com/t/WVgdlyq87IU

誰もがどのようにメモリの問題なしに、必要な出力を達成するためのアイデアを持っています。

答えて

0

カスタムImageViewを定義して、画像に色の枠線を追加することができます。ここに私のプロジェクト年前の1つは、それはAndroid OS用の円形画像ウィジェットの一種です。

https://github.com/avenwu/IndexImageView 

Screenshot

関連する問題