2017-02-21 8 views
0

나는 동그라미 안에 아이콘을 표시해야하지만 다른 반지 안에 반지를 그리려고했지만 할 수 없다. 어색한 자세로 시도했을 때 어떻게 할 수 있습니까?다른 반지 안에 반지를 그리는 방법

I tried to do like this but i can't

내 코드

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- Larger blue circle in back --> 
<item> 
    <shape android:shape="oval"> 
     <solid android:color="#f00"/> 
     <size 
      android:width="15dp" 
      android:height="15dp"/> 
    </shape> 
</item> 
<!-- Smaller red circle in front --> 
<item> 
    <shape android:shape="oval"> 
     <!-- transparent stroke = larger_circle_size - smaller_circle_size --> 
     <stroke android:color="@android:color/transparent" 
      android:width="10dp"/> 
     <solid android:color="#fff"/> 
     <size 
      android:width="1dp" 
      android:height="1dp"/> 
    </shape> 
</item> 
<item> 
    <shape android:shape="oval"> 
     <!-- transparent stroke = larger_circle_size - smaller_circle_size --> 
     <stroke android:color="@android:color/transparent" 
      android:width="11dp"/> 
     <solid android:color="#f00"/> 
     <size 
      android:width="1dp" 
      android:height="1dp"/> 
    </shape> 
</item> 

+0

는 당신이 시도 않은이 코드를 시도? (xmap없이'Bitmap'에 직접적으로) – Massimo

+0

No xml만을 사용 해보려고하지 않았습니다. – Sasi

답변

1
<?xml version="1.0" encoding="utf-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="oval"> 
      <size 
       android:width="200dp" 
       android:height="200dp" /> 
      <solid android:color="@android:color/transparent" /> 
      <stroke android:color="#ff0000" android:width="5dp"/> 
     </shape> 
    </item> 

    <item 
     android:left="5dp" 
     android:top="5dp" 
     android:right="5dp" 
     android:bottom="5dp"> 

     <shape android:shape="oval"> 
      <solid android:color="@android:color/transparent" /> 
      <stroke android:color="#5BB534" android:width="5dp"/> 
     </shape> 
    </item> 
</layer-list> 
+0

으로 업데이트되었습니다. – Sasi

1

내 코드를 사용해보십시오. 요구 사항에 따라 값을 다시 쓸 수 있습니다. 이 드로어 블을 배경에 추가 할 때 뷰가 정사각형인지 확인하십시오.

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item 
    android:left="6dip" 
    android:right="6dip"> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="oval"> 
     <stroke 
      android:width="3dip" 
      android:color="#f00" /> 
    </shape> 

</item> 

<item 
    android:bottom="80dip" 
    android:left="80dip" 
    android:right="80dip" 
    android:top="80dip"> 

    <shape android:shape="oval"> 
     <stroke 
      android:width="1dip" 
      android:color="#0f0" /> 
    </shape> 
</item> 

</layer-list> 

편집 추가 된 이미지 This what I get.

+0

@pandrideepak 빨간색 테두리 만 표시 – Sasi

+0

@Swathy : –

1

시도는 캔버스와 함께 그릴 수 :

DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); 
Bitmap bitmap = Bitmap.createBitmap((int) (15 * metrics.density), (int) (15 * metrics.density), Bitmap.Config.ARGB_8888); // 15dp x 15dp 
Canvas canvas = new Canvas(bitmap); 

// clear the bitmap with a transparent color 
canvas.drawColor(Color.TRANSPARENT); 
Paint paint = new Paint(); 
paint.setStrokeWidth(2 * metrics.density); // 2dp, the circle width 

// the external circle, large as the bitmap 
paint.setColor(Color.RED); 
canvas.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint); 

// the internal one, smaller than the first one 
paint.setColor(Color.GREEN); 
canvas.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2 - 3 * metrics.density, paint); 

당신은 몇 가지 숫자를 조정해야합니다. DisplayMetrics은 dp (픽셀이 아닌)의 크기를 변환하는 데 사용됩니다. 작업이 완료되면 BitmapBitmapDrawable과 함께보기 (예 : 배경)해야 사용할 수 있습니다.

0

는`Canvas`와

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item 
    android:left="3dp" 
    android:right="3dp"> 
    <shape android:shape="oval"> 
     <stroke android:width="5dp" 
      android:color="@android:color/holo_red_dark"> 

     </stroke> 
    </shape> 
</item> 
<item 
    android:bottom="10dp" 
    android:left="10dp" 
    android:right="10dp" 
    android:top="10dp"> 
    <shape android:shape="oval"> 
     <stroke android:width="10dp" 
      android:color="@android:color/holo_green_dark"> 

     </stroke> 
    </shape> 
</item>