2011-10-31 2 views
0

MapView에서 둥근 모서리를 만들려고합니다. 기본적으로이 방법을 사용할 수있는 것처럼 보이지 않기 때문에 기본적으로 내지도보기 위에 배경으로 레이아웃을 중첩합니다.외부에 정사각형 모양의 모서리가있는 드로어 블을 만드는 방법은 무엇입니까?

<?xml version="1.0" encoding="utf-8"?> 
<selector 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
    android:drawable="@drawable/bg_rounded_corner_transparent" /> 
</selector> 

및 드로어 블 내부는, 다음과 같이 정의됩니다 :

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="100dp" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" > 

<RelativeLayout 
    android:id="@+id/map_holder" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:background="@drawable/panel_rounded_corner_transparent" /> 
</RelativeLayout> 

내 둥근 모서리 당김은 다음과 같이 정의된다

<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
    <shape> 

     <solid 
     android:color="@color/transparent" /> 
     <stroke 
     android:width="1dp" 
     android:color="@color/darkgray" /> 
     <corners 
     android:radius="5dp" /> 
    </shape> 
    </item> 

</layer-list> 

그러나 문제가 지도가 직사각형으로 끝나고 테두리가 둥글어지기 때문에지도의 모서리가 내 임시 변두리 경계 뒤쪽에서 엿보입니다. 패널의 안쪽을 투명하게 유지하면서 테두리 외부에만 배경색을 설정하려면 어떻게합니까?

다음은 몇 가지 스크린 샷입니다.

이 스크린 샷은 문제가 무엇인지보고에 큰 선명도 빨간색 배경과지도를 대체합니다 :

이 스크린 샷은 오버레이 테두리로로 원래 "경계"지도를 보여줍니다

보시다시피 빨강 (및 확장하여지도)이 경계 밖으로 흐릅니다.

나는지도에 1DP 패딩을 추가 할 수 있습니다,하지만 당신은 여기에서 볼 수있는이 완전히 문제가 해결되지 않습니다

모서리가 둥글게되어 있기 때문에 enter image description here

이지도의 일부는 여전히 누수 아웃. 첫 번째 옵션보다 훨씬 좋지만 완벽하지는 않습니다 - 모서리에 1 개의 픽셀 도트가 있습니다.

enter image description here

+1

은 당신이 그것의 스크린 샷을 게시 할 수 있습니다 도와 드릴까요? – FoamyGuy

+0

패딩 사용. 따라서지도보기는 경계선 안에 있습니다. – blessenm

+0

사진이있는 게시물을 업데이트했습니다. Blessenm, 원래의 질문을 게시 한 직후 귀하의 제안을 생각했지만 문제가 완전히 해결되지는 않았습니다. – Catherine

답변

2

는 다음과 같이지도보기를 확장 시도를 해결해야합니다

private class MyMapView extends MapView { 

    public MyMapView(Context context, String apiKey) { 
     super(context, apiKey); 
    } 

    @Override 
    public void draw(Canvas canvas) { 
     Path path = new Path(); 
     RectF r = new RectF(0, 0, this.getWidth(), this.getHeight()); 
     path.addRoundRect(r, 12, 12, Path.Direction.CW); 
     canvas.clipPath(path); 
     super.draw(canvas); 
    } 
} 
당신은 조정해야 할 수도 있습니다

path.addRoundRect()의 반경

+0

완벽하게 작동합니다. –

0

안녕하세요, 저는 여기에 몇 시간 동안 놀았습니다. 여기에 transp와 함께 ImageView를위한 제 솔루션이 있습니다. arent 프레임 (타원형) 내부 및 단색 외부. 나는 그것이 타원형 모양이라는 것을 알고 있지만 rect와도 작동합니다.

내부에 두 개의 자식이있는 FrameLayout을 구현하십시오.shape_circle.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:drawable="@drawable/shape_circle_rect"/> 
    <item android:drawable="@drawable/shape_circle_oval"/> 
</layer-list> 

shape_circle_rect.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 
    <padding 
     android:left="-70dp" 
     android:top="-70dp" 
     android:right="-70dp" 
     android:bottom="-70dp"/> 

</shape> 

shape_circle_oval.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval" > 
    <stroke android:color="#ffffff" android:width="70dp"/> 
</shape> 

이 아니에게 여기

<FrameLayout 
     android:id="@+id/testLinearLayout" 
     android:layout_width="300dp" 
     android:layout_height="300dp"> 

     <ImageView 
      android:id="@+id/mainContentImage" 
      android:layout_width="300dp" 
      android:layout_height="300dp"/> 

     <LinearLayout 
      android:layout_width="300dp" 
      android:layout_height="300dp" 
      android:background="@drawable/shape_circle"> 
     </LinearLayout> 
</FrameLayout> 

된다 : 그래서 모양은 이미지 뷰를 중복합니다 정확히 무엇을 검색하지만 도움이 될 수 있습니다. 이 워킹됩니다

관련 문제