2016-06-06 3 views
3

드로어 블에서 투명화를 사용하지 않고 셰이프 또는 사각형을 만들려고합니다.안드로이드에서 픽셀 투명성이없는 드로어 블에서 셰이프 만들기

여기에서 볼 수 있듯이 다음 단추는 테두리에 투명도가 있습니다. 내 문제는 패널 편집기를 만드는 중이며 위젯을 이동할 때 위젯이 겹치지 않도록하려는 것입니다. 는이를 달성하기 위해, 나는 방법을 사용하고 있습니다 : Rect.intersects(Rect)

enter image description here

그러나, 사용되는 사각형은 (투명도 포함) 전체 당김의 모양과 너무 많은 빈 공간을 만들 수 있습니다.

편집 : 더 많은 정보

가 여기 내 편집기, 난 중첩을 피하기 위해가 성공하지만 중첩는 드로어 블 (사진)의 모양에 기지입니다. 그리고 그림의 투명성은 내 패널에 빈 공간을 만듭니다.

enter image description here

및 tempRect은 아마 충분히 명확하지 않았다 현재 이동 위젯

public boolean checkCollision(Rect tempRect,ArrayList<IHMObject> listWidget) { 
    float dimen = activity.getResources().getDimension(R.dimen.abc_action_bar_default_height)+ 38; 
    for(IHMObject widget :listWidget){ 
     int[]location = new int[2]; 
     View v =(View)widget.getView(); 
     v.getLocationInWindow(location); 
     //vérifier la postion du widget en fonctions des autres widgets de l'IHM 
     Rect staticRect = new Rect(location[0],location[1]-(int)dimen,location[0]+v.getWidth(),location[1]+v.getHeight()-(int)dimen); 
     if (this.id!=widget.id){ 
      if (staticRect.intersect(tempRect)) { 
       //il y a une collision entre les deux rectangles 
       return true; 
      } 
     } 

    } 
    return false; 
} 

답변

0
Create a round_shape.xml file in drawable folder like below 


<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" android:padding="10dp"> 
    <!-- you can use any color you want I used here gray color--> 
    <solid android:color="#ABABAB"/> 
    <corners android:radius="10dp"/> 
</shape> 

Set this Draweble like below 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 
    android:textColor="#ffffff" 
    android:src="@drawable/round_shape" // here is your round_shape 
    android:background="#000000" 
    android:text="Buttons" /> 
+0

에게 내 체크 충돌 코드는 내가 기존에서 모양 또는 사각형을 만들어야합니다 그리기 가능으로 저장된 그림은 그림의 투명도없이 저장됩니다. –