私はこのような六角形のリストビューを作成したいと考えています。 androidで六角形のリストビューを作成する方法
答えて
あなたがXMLで子のレイアウトにこの六角形のImageViewのを使用するとマージン
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"/>
希望これは
これは、画像ビューのためのhttp://stackoverflow.com/questions/22601400/how-to-give-hexagon-shape-to-imageview –
ya彼はリストの子ビューのためにその画像ビューを使用し、いくつかを追加することができます偶数奇数位置に基づくマージン(正と負) – 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. バックグラウンドで四角形の六角形を作成する方法は?
- 2. アンドロイドで六角形の画像ビューを作成するには?
- 3. CSSで六角形を作成する、対称性
- 4. 六角形のパンコントロール
- 5. 背景イメージのある丸い六角形の作成方法は?
- 6. 正方形のXYグリッド六角形の頂点からの六角ラベル
- 7. UICollectionViewで六角形のイメージを描画する方法
- 8. Pythonで六角形グラフの点をプロットする方法は?
- 9. EmguCvでペンタゴンと六角形を検出する方法
- 10. Android - Androidで六角形を作成し、アニメーションで回転するにはどうすればよいですか?
- 11. 六角形グリッドを描画/管理する方法は?
- 12. 六角形の行列ポリゴンですか?
- 13. イメージピクセルを正方形から六角形に変換する
- 14. タートルモジュールで円と六角形を描く方法は?
- 15. 六角形タイルをズームインするjavascript
- 16. vb.netでの六角形の描画
- 17. 同心円の六角形を描く方法は?
- 18. Androidカスタムコンテナ(六角)付属アダプタ
- 19. 六角形のグループの概要
- 20. 非空白の六角形のヘックスビンセンター
- 21. CSS3アニメーション六角形のバブル効果
- 22. 六角形(ビン)画像のニューラルネットワーク?
- 23. タイルマップされた六角形の座標
- 24. タイル張りの平たい六角形
- 25. GPUImage:六角形内の平均色を決定する方法は?
- 26. 中心の六角形格子の生成
- 27. iosで三角形のオブジェクトを作成する方法
- 28. 多角形であるCCSpriteを作成する方法
- 29. 我々は六角形ラティス持っ
- 30. 、国境を六角形にしますが、私は国境を持つ六角形の形状を作りたい
を助けます(http://stackoverflow.com [この]を参照してください。/questions/8840729/android-hexagon-grid)を参照してください。たぶんこれはあなたを助けるでしょう –