我有四個imageview視圖鰭狀肢,相機中捕獲的圖像設置爲每個imageview。使用showNext()方法查看viewflipper中的所有子項。我必須獲取viewflipper的當前視圖並設置當前圖像視圖的壁紙。如何確定viewflipper的當前視圖?
下面是我用來獲取當前視圖並設置爲壁紙的代碼。
package com.example.websamples;
import java.io.IOException;
import java.util.ArrayList;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ViewFlipper;
public class Photo extends Activity implements OnClickListener {
ViewFlipper vfImageViews;
ImageView ivCapture1, ivCapture2, ivCapture3, ivCapture4;
ImageButton ibCamera;
Button bSetWall;
final int cameraData = 0;
Bitmap bmpImageView0, bmpImageView1, bmpImageView2, bmpImageView3;
int iSetWallpaper;
int iStatus = 1;
ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
ivCapture1 = (ImageView) findViewById(R.id.ivCapture1);
ivCapture2 = (ImageView) findViewById(R.id.ivCapture2);
ivCapture3 = (ImageView) findViewById(R.id.ivCapture3);
ivCapture4 = (ImageView) findViewById(R.id.ivCapture4);
ibCamera = (ImageButton) findViewById(R.id.ibCamera);
bSetWall = (Button) findViewById(R.id.bSetWall);
vfImageViews = (ViewFlipper) findViewById(R.id.vfImageViews);
ibCamera.setOnClickListener(this);
bSetWall.setOnClickListener(this);
vfImageViews.setOnClickListener(this);
// vfImageViews.setFlipInterval(5000);
// vfImageViews.startFlipping();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.vfImageViews:
vfImageViews.showNext();
break;
case R.id.ibCamera:
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, cameraData);
break;
case R.id.bSetWall:
try {
iSetWallpaper = vfImageViews.indexOfChild(vfImageViews
.getCurrentView());
// WallpaperManager myWallpaperManager =
// WallpaperManager.getInstance(getApplicationContext());
// myWallpaperManager.setResource(iSetWallpaper);
getApplicationContext().setWallpaper(
bitmapArray.get(iSetWallpaper));
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == cameraData) {
Bundle extras = data.getExtras();
if (iStatus == 1) {
bmpImageView0 = (Bitmap) extras.get("data");
bitmapArray.add(bmpImageView0);
ivCapture1.setImageBitmap(bmpImageView0);
vfImageViews.setDisplayedChild(vfImageViews
.indexOfChild(findViewById(R.id.ivCapture1)));
iStatus++;
} else if (iStatus == 2) {
bmpImageView1 = (Bitmap) extras.get("data");
bitmapArray.add(bmpImageView1);
ivCapture2.setImageBitmap(bmpImageView1);
vfImageViews.setDisplayedChild(vfImageViews
.indexOfChild(findViewById(R.id.ivCapture2)));
iStatus++;
} else if (iStatus == 3) {
bmpImageView2 = (Bitmap) extras.get("data");
bitmapArray.add(bmpImageView2);
ivCapture3.setImageBitmap(bmpImageView2);
vfImageViews.setDisplayedChild(vfImageViews
.indexOfChild(findViewById(R.id.ivCapture3)));
iStatus++;
} else if (iStatus == 4) {
bmpImageView3 = (Bitmap) extras.get("data");
bitmapArray.add(bmpImageView3);
ivCapture4.setImageBitmap(bmpImageView3);
vfImageViews.setDisplayedChild(vfImageViews
.indexOfChild(findViewById(R.id.ivCapture4)));
iStatus = 1;
}
}
}
}
}
我的申請力停止這裏 iSetWallpaper = vfImageViews.indexOfChild(vfImageViews.getCurrentView());
請更正代碼出錯的地方。
難道有人對你回答? – Senthil