在我的视图中,我想移动从ListView中获取的不同位图,但是使用此方法我一次只能拖动一个
这是我的方法:
vestitiView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
text = (TextView) view.findViewById(R.id.list_item_name);
imageView = (ImageView) view.findViewById(R.id.dressImage);
bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
dress = bitmapDrawable.getBitmap();
dragDrop();
eliminated = false;
}
});
private void dragDrop() {
dressAdded.add(Bitmap.createBitmap(dress,0,0,
dress.getWidth(),dress.getHeight()));
dressArea = new DressAreaView(this,dressAdded);
frame.addView(dressArea);
}
private class DressAreaView extends View {
private GestureDetector gestures;
private Matrix translate;
private Bitmap dress;
private Matrix animateStart;
private Interpolator animateInterpolator;
private long startTime;
private long endTime;
private float totalAnimDx;
private float totalAnimDy;
public void onAnimateMove(float dx, float dy, long duration) {
animateStart = new Matrix(translate);
animateInterpolator = new OvershootInterpolator();
startTime = System.currentTimeMillis();
endTime = startTime + duration;
totalAnimDx = dx;
totalAnimDy = dy;
post(new Runnable() {
@Override
public void run() {
onAnimateStep();
}
});
}
private void onAnimateStep() {
long curTime = System.currentTimeMillis();
float percentTime = (float) (curTime - startTime)
/ (float) (endTime - startTime);
float percentDistance = animateInterpolator
.getInterpolation(percentTime);
float curDx = percentDistance * totalAnimDx;
float curDy = percentDistance * totalAnimDy;
translate.set(animateStart);
onMove(curDx, curDy);
if (percentTime < 1.0f) {
post(new Runnable() {
@Override
public void run() {
onAnimateStep();
}
});
}
}
public void onMove(float dx, float dy) {
translate.postTranslate(dx, dy);
invalidate();
}
public void onResetLocation() {
translate.reset();
invalidate();
}
public void onSetLocation(float dx, float dy) {
translate.postTranslate(dx, dy);
}
public DressAreaView(Context context,List<Bitmap> dress) {
super(context);
translate = new Matrix();
gestures = new GestureDetector(DressRoom.this,
new GestureListener(this));
for(Bitmap b : dress) {
this.setBitmap(b);
}
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(dress, translate, null);
Matrix m = canvas.getMatrix();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return gestures.onTouchEvent(event);
}
public void setBitmap(Bitmap dressing) {
this.dress = dressing;
this.translate.postTranslate(0, 0);
}
}
这是我的活动布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="rp.com.dressroom.View.DressRoom"
android:background="@drawable/bg">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/view"
android:layout_marginTop="40dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/personaView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</FrameLayout>
<ListView
android:layout_width="166dp"
android:layout_height="fill_parent"
android:id="@+id/listView"
android:layout_alignParentBottom="true"
android:layout_marginLeft="245dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#00ffffff"
android:layout_marginTop="30dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkOut"
android:layout_alignBottom="@+id/buttonShowTutorial"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#00FFFFFF"
android:src="@drawable/ic_action_add_shopping_cart" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/remove"
android:layout_gravity="left|top"
android:background="#00FFFFFF"
android:src="@drawable/reset"
android:layout_marginLeft="185dp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#a79f9f"
android:id="@+id/acquisti"
android:visibility="gone">
<ListView
android:layout_width="231dp"
android:layout_height="383dp"
android:id="@+id/listView2"
android:layout_gravity="left|top"
android:layout_marginLeft="80dp" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="CkeckOut"
android:id="@+id/checkOutBtn"
android:layout_gravity="left|bottom" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Continua"
android:id="@+id/continua"
android:layout_gravity="right|bottom" />
</FrameLayout>
</FrameLayout>
我如何使用该类移动多个位图?