나는 이런 식으로 육각형리스트 뷰를 만들려고합니다. android에서 육각형리스트 뷰를 만드는 방법
답변
당신은 아이의 레이아웃이 육각형 이미지 뷰를 사용하여 조정할 수 있습니다 마진 XML에
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.Region;
import android.util.AttributeSet;
import android.widget.ImageView;
public class HexagonMaskView extends ImageView {
private Path hexagonPath;
private Path hexagonBorderPath;
private Paint mBorderPaint;
public HexagonMaskView(Context context) {
super(context);
init();
}
public HexagonMaskView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public HexagonMaskView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
this.hexagonPath = new Path();
this.hexagonBorderPath = new Path();
this.mBorderPaint = new Paint();
this.mBorderPaint.setColor(Color.WHITE);
this.mBorderPaint.setStrokeCap(Paint.Cap.ROUND);
this.mBorderPaint.setStrokeWidth(50f);
this.mBorderPaint.setStyle(Paint.Style.STROKE);
}
public void setRadius(float radius) {
calculatePath(radius);
}
public void setBorderColor(int color) {
this.mBorderPaint.setColor(color);
invalidate();
}
private void calculatePath(float radius) {
float halfRadius = radius/2f;
float triangleHeight = (float) (Math.sqrt(3.0) * halfRadius);
float centerX = getMeasuredWidth()/2f;
float centerY = getMeasuredHeight()/2f;
this.hexagonPath.reset();
this.hexagonPath.moveTo(centerX, centerY + radius);
this.hexagonPath.lineTo(centerX - triangleHeight, centerY + halfRadius);
this.hexagonPath.lineTo(centerX - triangleHeight, centerY - halfRadius);
this.hexagonPath.lineTo(centerX, centerY - radius);
this.hexagonPath.lineTo(centerX + triangleHeight, centerY - halfRadius);
this.hexagonPath.lineTo(centerX + triangleHeight, centerY + halfRadius);
this.hexagonPath.close();
float radiusBorder = radius - 5f;
float halfRadiusBorder = radiusBorder/2f;
float triangleBorderHeight = (float) (Math.sqrt(3.0) * halfRadiusBorder);
this.hexagonBorderPath.reset();
this.hexagonBorderPath.moveTo(centerX, centerY + radiusBorder);
this.hexagonBorderPath.lineTo(centerX - triangleBorderHeight, centerY + halfRadiusBorder);
this.hexagonBorderPath.lineTo(centerX - triangleBorderHeight, centerY - halfRadiusBorder);
this.hexagonBorderPath.lineTo(centerX, centerY - radiusBorder);
this.hexagonBorderPath.lineTo(centerX + triangleBorderHeight, centerY - halfRadiusBorder);
this.hexagonBorderPath.lineTo(centerX + triangleBorderHeight, centerY + halfRadiusBorder);
this.hexagonBorderPath.close();
invalidate();
}
@Override
public void onDraw(Canvas c) {
c.drawPath(hexagonBorderPath, mBorderPaint);
c.clipPath(hexagonPath, Region.Op.INTERSECT);
c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
super.onDraw(c);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
calculatePath(Math.min(width/2f, height/2f) - 10f);
}
}
<YourpakageName.HexagonMaskView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bear"
android:background="@android:color/holo_green_light"/>
희망이
thisview imageview http://stackoverflow.com/questions/22601400/how-to-give-hexagon-shape-to-imageview –
예, 그는 자식보기 목록에 해당 이미지보기를 사용할 수 있습니다. 여백 순위 (양수 및 음수)도 홀수 위치를 기준으로 – Redman
이해합니다. 그러나 사용자는 '육각형 목록보기 작성 방법'을 묻습니다. –
이봐 그 벡터 이미지를 사용 : -
<vector android:height="24dp"
android:viewportHeight="628.0"
android:viewportWidth="726.0"
android:width="27dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="#00ffffff"
android:pathData="m723,314c-60,103.9 -120,207.8 -180,311.8 -120,0 -240,0 -360,0C123,521.8 63,417.9 3,314 63,210.1 123,106.2 183,2.2c120,0 240,0 360,0C603,106.2 663,210.1 723,314Z"
android:strokeColor="#000000"
android:strokeWidth="4" />
희망이 help.Happy 코딩.
- 1. Android에서 맞춤 웹 뷰를 만드는 방법은 무엇입니까?
- 2. Android에서 곡선 뷰를 만드는 방법은 무엇입니까?
- 3. android에서 이미지 뷰를 회전하는 방법
- 4. 이미지 뷰를 만드는 방법
- 5. android에서 섹션 헤더가 포함 된 확장형 목록 뷰를 만드는 방법
- 6. Android에서 TV 가이드보기를 만드는 방법
- 7. android에서 공유보기를 만드는 방법
- 8. Android에서 레이아웃을 만드는 방법
- 9. android에서 확대경을 만드는 방법
- 10. android에서 framework.odex를 만드는 방법
- 11. android에서 연락처를 만드는 방법
- 12. Android에서 동그라미를 만드는 방법
- 13. android에서 openssl을 만드는 방법
- 14. UIProgress 뷰를 원형으로 만드는 방법
- 15. 목록보기의 텍스트 뷰를 만드는 방법
- 16. PHP에서 테이블 뷰를 만드는 방법
- 17. 반원형을 만드는 방법 android에서 ProgressBar을 만드는 방법
- 18. android에서 사용자 정의보기를 만드는 방법
- 19. android에서 홀더 객체의 뷰를 변경하는 방법
- 20. webview로 뷰를 애니메이션하는 방법 android에서 스크롤
- 21. android에서 이미지 뷰를 새로 고치는 방법
- 22. android에서 recycler 뷰에 다중 뷰를 추가하는 방법
- 23. Android에서 2 차원 스크롤 뷰를 만드는 올바른 방법은 무엇입니까?
- 24. android에서 중첩 된 리사이클 뷰를 만드는 방법은 무엇입니까?
- 25. android에서 뷰의 애니메이션을 간단히 만드는 방법
- 26. android에서 다양한 수의 textview를 만드는 방법
- 27. android에서 위젯으로 Google지도를 만드는 방법
- 28. android에서 유체 모션을 만드는 방법
- 29. android에서 회전 아이콘을 만드는 방법
- 30. android에서 동적 레이아웃을 만드는 방법
은 [이] (참조 http://stackoverflow.com하는 데 도움이/questions/8840729/android-hexagon-grid). 어쩌면이 도움이 될 것입니다 –