Xin chào, tôi đang sử dụng tiện ích Thư viện để hiển thị hình ảnh được tải xuống từ internet.Thư viện Android zoom in/out
để hiển thị một số hình ảnh và tôi muốn có thu phóng dần dần trong khi mọi người trượt lên và xuống trên màn hình. Tôi biết làm thế nào để thực hiện các sự kiện liên lạc điều duy nhất tôi không biết làm thế nào để làm cho toàn bộ xem gallery phát triển dần dần. Tôi không muốn phóng to một hình ảnh Tôi muốn toàn bộ thư viện thu phóng dần dần.
EDIT3: Tôi quản lý để thu phóng phần hiển thị của bộ sưu tập nhưng vấn đề là tôi cần tìm cách để thư viện tìm hiểu về nó và cập nhật cho các trẻ khác.
Điều gì sẽ xảy ra nếu 3 hình ảnh hiển thị sau đó bạn bắt đầu phóng to và thư viện sẽ thu nhỏ hơn, do đó, làm hình ảnh nhưng những gì Tôi muốn trong trường hợp này là nhiều hình ảnh hơn để hiển thị nhưng tôi không biết để đạt được hiệu ứng mong muốn này. Đây là toàn bộ mã:
public class Gallery1 extends Activity implements OnTouchListener {
private static final String TAG = "GalleryTest";
private float zoom=0.0f;
// Remember some things for zooming
PointF start = new PointF();
PointF mid = new PointF();
Gallery g;
LinearLayout layout2;
private ImageAdapter ad;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_1);
layout2=(LinearLayout) findViewById(R.id.layout2);
// Reference the Gallery view
g = (Gallery) findViewById(R.id.gallery);
// Set the adapter to our custom adapter (below)
ad=new ImageAdapter(this);
g.setAdapter(ad);
layout2.setOnTouchListener(this);
}
public void zoomList(boolean increase) {
Log.i(TAG, "startig animation");
AnimatorSet set = new AnimatorSet();
set.playTogether(
ObjectAnimator.ofFloat(g, "scaleX", zoom),
ObjectAnimator.ofFloat(g, "scaleY", zoom)
);
set.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
set.setDuration(100).start();
}
public class ImageAdapter extends BaseAdapter {
private static final int ITEM_WIDTH = 136;
private static final int ITEM_HEIGHT = 88;
private final int mGalleryItemBackground;
private final Context mContext;
private final Integer[] mImageIds = {
R.drawable.gallery_photo_1,
R.drawable.gallery_photo_2,
R.drawable.gallery_photo_3,
R.drawable.gallery_photo_4,
R.drawable.gallery_photo_5,
R.drawable.gallery_photo_6,
R.drawable.gallery_photo_7,
R.drawable.gallery_photo_8
};
private final float mDensity;
public ImageAdapter(Context c) {
mContext = c;
// See res/values/attrs.xml for the <declare-styleable> that defines
// Gallery1.
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 1);
a.recycle();
mDensity = c.getResources().getDisplayMetrics().density;
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
convertView = new ImageView(mContext);
imageView = (ImageView) convertView;
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(
(int) (ITEM_WIDTH * mDensity + 0.5f),
(int) (ITEM_HEIGHT * mDensity + 0.5f)));
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mImageIds[position]);
return imageView;
}
}
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE
&& event.getPointerCount() > 1) {
midPoint(mid, event);
if(mid.y > start.y){
Log.i(TAG, "Going down (Math.abs(mid.y - start.y)= "+(Math.abs(mid.y - start.y))+" and zoom="+zoom); // going down so increase
if ((Math.abs(mid.y - start.y) > 10) && (zoom<2.5f)){
zoom=zoom+0.1f;
midPoint(start, event);
zoomList(true);
}
return true;
}else if(mid.y < start.y){
Log.i(TAG, "Going up (Math.abs(mid.y - start.y)= "+(Math.abs(mid.y - start.y))+" and zoom="+zoom); //smaller
if ((Math.abs(mid.y - start.y) > 10) &&(zoom>0.1)){
midPoint(start, event);
zoom=zoom-0.1f;
zoomList(false);
}
return true;
}
}
else if (event.getAction() == MotionEvent.ACTION_POINTER_DOWN) {
Log.e(TAG, "Pointer went down: " + event.getPointerCount());
return true;
}
else if (event.getAction() == MotionEvent.ACTION_UP) {
Log.i(TAG, "Pointer going up");
return true;
}
else if (event.getAction() == MotionEvent.ACTION_DOWN) {
Log.i(TAG, "Pointer going down");
start.set(event.getX(), event.getY());
return true;
}
return false;
// indicate event was handled or not
}
private void midPoint(PointF point, MotionEvent event) {
float x = event.getX(0) + event.getX(1);
float y = event.getY(0) + event.getY(1);
point.set(x/2, y/2);
}
Tôi nhận thấy rằng tôi có thể sẽ mở rộng Thư viện hoặc thậm chí một nhóm Chế độ xem khác hoặc tạo lớp học của riêng tôi. ...
EDIT4: Tôi không biết liệu câu hỏi của anh ấy có đủ rõ ràng không. Dưới đây là một ví dụ về trạng thái:
Nhà nước một: trạng thái ban đầu, chúng tôi có 3 hình ảnh theo quan điểm
Nhà nước 2: chúng tôi phát hiện chạm thẳng đứng đi lên với 2 ngón tay = chúng ta phải thu nhỏ
nhà nước 3: chúng tôi bắt đầu phóng to = hoạt hình trên thư viện hoặc trên trẻ em ???
trạng thái 4: phòng trưng bày phát hiện rằng đó là 3 đứa con nhỏ
nhà nước 5: bộ sưu tập thêm 1/nhiều trẻ em theo không gian có sẵn mới
Cập nhật lần cuối: Nhờ tất cả những gì đã đăng tải nhưng tôi có cuối cùng đạt đến một kết luận và đó là không sử dụng Phòng triển lãm ở tất cả: 1. Nó bị phản đối 2. Nó không đủ tùy chỉnh cho trường hợp của tôi
Nếu bạn muốn để animate nhiều hình ảnh cùng một lúc bạn có thể muốn xem xét sử dụng OpenGL , Tôi đang dùng libgdx thư viện: https://github.com/libgdx/libgdx
cảm ơn Akos vì câu trả lời của bạn. Tôi đã thử nó nhưng như tôi sử dụng hình ảnh động trên bộ sưu tập của ông kết quả là giống như trước: có thể nhìn thấy được schrinks nhưng không có quan điểm mới được rút ra.Nếu tôi áp dụng hoạt ảnh cho một chế độ xem đó và chỉ thu phóng. Nếu tôi sử dụng scaleX/scaleY cùng một điều .... Tôi đã quyết định tạo Surfaceview của riêng mình và chỉ vẽ bitmap – vallllll
Xin chào, Bạn có thể qua đây đầy đủ mã không. – Hasmukh
Xin vui lòng đặt mã đầy đủ của bạn ở đây ... tôi cần nó khẩn trương ... Cảm ơn trước! –