2

プロジェクトでは、プロフィール画像やその他の画像を別ので表示する必要があります。そのような形を作成する方法と、その中に画像を表示する方法がわかりません。このタイプの形状もリスト ビューに配置する必要があります。私に提案してください。

前もって感謝します。

4

3 に答える 3

1

Android用のソリューションを試してみました。私がしたことは何でも共有しています。

  • Viewクラスを拡張したクラスCustomShapeを作成しました。
  • onDraw() メソッドをオーバーライドします。
  • Paint と Path オブジェクトを作成しました。
  • 座標に線を引きました。
  • リソースからビットマップを作成して、シェイプ内のイメージを表示しました。
  • BitmapShader オブジェクトを作成し、それを Paint に設定しました。
  • Path と Paint オブジェクトでキャンバスを描画します。
  • XML でレイアウトを作成し、CustomeShape を追加しました。
  • CustomShape オブジェクトを作成してインスタンス化しました。

CustomShape クラスのコードは次のとおりです。

public class CustomShape extends View {
Bitmap bitmap;
BitmapShader bitmapShader;

public CustomShape(Context context) {
    super(context);
    // TODO Auto-generated constructor stub

}

public CustomShape(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomShape(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}


@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);

    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    Path pth = new Path();
    pth.moveTo(0, 0);

    pth.lineTo(100, 0);
    pth.lineTo(70, 100);
    pth.lineTo(0, 100);

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
            R.drawable.ppp);
    bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP,
            Shader.TileMode.REPEAT);
    p.setShader(bitmapShader);
    canvas.drawPath(pth, p);
}

MainActivity.java のコードは次のとおりです。

public class MainActivity extends Activity {

CustomShape customShape;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_main);

    customShape = (CustomShape) findViewById(R.id.customeShape);

    }

}

レイアウトはこちら

 <com.example.btndemo.CustomShape
      android:id="@+id/customeShape"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
于 2014-09-05T12:13:02.133 に答える
1

そのようなことを試してください:

profileImageview=[[UIImageView alloc]initWithFrame:CGRectMake(2,10,100,80)];
    UIBezierPath *path = [UIBezierPath new];
    [path moveToPoint:(CGPoint){0, 0}];
    [path addLineToPoint:(CGPoint){100, 0}];
    [path addLineToPoint:(CGPoint){70, 80}];
    [path addLineToPoint:(CGPoint){0, 80}];
    [path addLineToPoint:(CGPoint){0, 0}];

     CAShapeLayer *mask = [CAShapeLayer new];
    mask.frame = profileImageview.bounds;
    mask.path = path.CGPath;

    // Mask the imageView's layer with this shape
    profileImageview.layer.mask = mask;
于 2014-09-05T10:00:07.790 に答える