웹상에서 이미지의 우선순위를 조정할 때는 z-index를 사용하면 됩니다만, 안드로이드에는 아쉽게도 z-index가 없습니다. 그래서 아쉬운데로 컨트롤하기 위해서는 아래와같은 방법으로 컨트롤해주면 됩니다.
1 | imgView1.bringToFront(); |
위와같이 .bringToFront()를 사용하면 메소드를 사용한 이미지뷰에 가장 우선순위를 줘 맨위에 보이도록 컨트롤이 가능합니다.
웹상에서 이미지의 우선순위를 조정할 때는 z-index를 사용하면 됩니다만, 안드로이드에는 아쉽게도 z-index가 없습니다. 그래서 아쉬운데로 컨트롤하기 위해서는 아래와같은 방법으로 컨트롤해주면 됩니다.
1 | imgView1.bringToFront(); |
위와같이 .bringToFront()를 사용하면 메소드를 사용한 이미지뷰에 가장 우선순위를 줘 맨위에 보이도록 컨트롤이 가능합니다.
ImageView(이미지뷰)의 테두리에 라운드를 주고 싶을땐 아래와 같이 처리하면됩니다.
먼저 ImageView를 상속받아 아래와 같이 재정의 하는 Java 클래스를 만들어줍니다.
※ RadiusImageView.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import android.content.Context; import android.graphics.Canvas; import android.graphics.Path; import android.graphics.RectF; import android.util.AttributeSet; import android.widget.ImageView; public class RadiusImageView extends ImageView { // 라운드처리 강도 값을 크게하면 라운드 범위가 커짐 public static float radius = 18 .0f; public RadiusImageView(Context context) { super (context); } public RadiusImageView(Context context, AttributeSet attrs) { super (context, attrs); } public RadiusImageView(Context context, AttributeSet attrs, int defStyle) { super (context, attrs, defStyle); } @Override protected void onDraw(Canvas canvas) { Path clipPath = new Path(); RectF rect = new RectF( 0 , 0 , this .getWidth(), this .getHeight()); clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW); canvas.clipPath(clipPath); super .onDraw(canvas); } } |
※ 레이아웃 xml 파일 (ex:activity_main.xml)
<com.example.image_crop2.RadiusImageView
android:id="@+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp"
android:src="@drawable/img5" />
위의 xml값을 보시면 패키지명.RadiusImageView로 선언해서 ImageView와 같은 방식으로 쓰시면됩니다.
※ 프로그래밍에서 참조해서 컨트롤을 하시려면...
1 2 3 4 5 6 7 8 9 10 11 12 13 | public class MainActivity extends Activity { RadiusImageView iv1; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv1 = (RadiusImageView) findViewById(R.id.iv1); } } |
위와 같이 RadiusImageView로 참조해서 사용하시면 됩니다.
출처 : http://stackoverflow.com/questions/18229358/bitmap-in-imageview-with-rounded-corners
비슷한 포스팅 : Bitmap 테두리 라운드처리하기