Có bất kỳ cách nào để biết chế độ xem mong muốn được hiển thị trên ViewFlipper
khi đang lật? Tôi gặp vấn đề này: ViewFlipper
của tôi chứa một số hình ảnh và một video. Tôi muốn rằng khi viewflipper hiển thị Videoview
với video, ViewFlipper
để dừng lật và Video để bắt đầu phát. Điều này chỉ hoạt động khi video được hiển thị lần đầu tiên. Sau đó, video được hiển thị dưới dạng hình ảnh và tôi không biết cách ghi lại khoảnh khắc khi video được hiển thị. Bất cứ ai có thể giúp tôi, xin vui lòng?Xem chế độ xem hiện tại của ViewFlipper khi đang lật
Sau đây là cách tôi cư ViewFlipper:
private void populate() {
for (int i = 0; i < jArray.length(); i++) {
System.out.println("lungime " + jArray.length());
LinearLayout l = new LinearLayout(this);
l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
l.setBackgroundColor(0x000000);
l.setOrientation(LinearLayout.VERTICAL);
vf.addView(l);
File f = new File(Environment.getExternalStorageDirectory()
+ "/Images" + "/");
File[] files = f.listFiles();
if (files[i].getName().equals("Video" + idPhotos[i])) {
System.out.println("Video to Viewflipper");
System.out.println("Video Path " + files[i].getPath());
myVideoView = new VideoView(this);
myVideoView.setVideoPath(files[i].getPath());
myVideoView.requestFocus();
myVideoView.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
l.setBackgroundColor(Color.BLACK);
myVideoView.setKeepScreenOn(true);
myVideoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
vf.stopFlipping();
}
});
myVideoView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
downXValue = event.getX();
break;
}
case MotionEvent.ACTION_UP: {
currentX = event.getX();
if (downXValue == currentX) {
Intent intent = new Intent(getBaseContext(),
FinActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
}
}
return true;
}
});
myVideoView
.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
vf.startFlipping();
}
});
vf.stopFlipping();
myVideoView.start();
myVideoView.setId(i);
l.addView(myVideoView);
l.setId(i);
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 3;
options.inPurgeable = true;
bitmap = BitmapFactory.decodeFile(files[i].getPath());
img = new ImageView(this);
img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
img.setImageBitmap(bitmap);
img.setOnTouchListener(this);
l.addView(img);
l.setId(i);
img = null;
}
}
và trên phương pháp onCreate() Tôi đã này:
if (ff.exists() && (files.length == jArray.length())) {
populate();
vf.setOutAnimation(AnimationUtils.loadAnimation(
getBaseContext(), R.anim.push_left_out));
vf.setInAnimation(AnimationUtils.loadAnimation(
getBaseContext(), R.anim.push_left_in));
vf.startFlipping();
}
(tôi gọi cư() phương pháp duy nhất một lần trong một thời gian, có lẽ đây là vấn đề)
Bất kỳ ý tưởng nào đều được hoan nghênh. Cảm ơn trước.
Cảm ơn bạn đã có ý tưởng. Nó giúp tôi giải quyết vấn đề của mình :) – Gabrielle