私は初心者の Android 開発者なので、この質問に対する答えが明らかである場合は申し訳ありません。
に 2 枚の写真を追加したいimageView
。最初の画像は大きくなり、その位置は変わりません。そして2番目は小さくなり、その位置は垂直方向に変化します(配置できる場所には16の組み合わせがあると思います)。2 番目の画像の位置は、ユーザーがボタンを押したときにのみ変更されます。2 つの画像を 1 つのビットマップに設定してから描画する方法はありますImageView
か?
要件がある場合set two pictures into one bitmap and then draw them to ImageView
は、次のことをお勧めします。
大きなビットマップからキャンバスを作成し、その上に小さなビットマップを描画し、描画したビットマップをイメージ ビューに表示できます。
タフに描く位置を計算しなければなりません。
Bitmap largeImage; // Get it with your own approach, this refers to larger image
Bitmap smallImage; // Get it with your own approach, this refers to small image
ImageView yourImageView;
Canvas canvas = new Canvas(largeImage);
//0f and 0f refers to coordinates of drawing, you may want to do some calculation here
// since you have like 16 different positions
canvas.drawBitmap(smallImage, 0f, 0f, null);
yourImageView.setImageBitmap(largeImage);
ImageView は、単一のビットマップに関連付けられています。自分でビットマップを描画して ImageView に渡すか、背景用の静的イメージと必要な場所に動的イメージを含む gridlayout (または gridview) などの他のコンポーネントを使用できます。
質問が適切でなかった場合は申し訳ありません...
FrameLayout
2本で使用ImageView
。そして、ビットマップをそのイメージビューに設定します。
あなたがすべきことは次のとおりです.XMLは次のとおりです。
<RelativeLayout
android:id="@+id/view_base"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/iv_parent"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/circle" />
<ImageView
android:id="@+id/iv_child"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
2 つのメソッドを含むコードを次に示します。
//This is what I recommend
RelativeLayout view_base=(RelativeLayout)findViewById(R.id.view_base);
ImageView iv_parent=(imageView)findViewById(R.id.iv_parent);
ImageView iv_child=(imageView)findViewById(R.id.iv_child);
yourButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
iv_child.setBackgroundResource(R.drawable.image);
}
});
//This is how you want it
RelativeLayout view_base=(RelativeLayout)findViewById(R.id.view_base);
ImageView iv_parent=(imageView)findViewById(R.id.iv_parent);
ImageView iv_child=(imageView)findViewById(R.id.iv_child);
ImageView iv_single=(imageView)findViewById(R.id.iv_single);
yourButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
iv_child.setBackgroundResource(R.drawable.image);
iv_single.setImageBitmap(getMergedBitmap());
}
});
//This method will convert view to bitmap
private Bitmap getMergedBitmap(){
view_base.setDrawingCacheEnabled(true);
view_base.buildDrawingCache();
return view_base.getDrawingCache()
}