我正在製作Android應用程序,每當應用程序運行時,都會出現包含多個組件的活動屏幕。現在,這個活動有幾個不同的組件。其中一個是顯示來自畫廊的不同圖像的圖像視圖。目前,這些圖像通過觸摸手勢而改變。但我想要使用左右刷卡來實現相同的功能。這裏是我的代碼:使用左右滑動來更改圖像
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import java.util.Collection;
public class pictures extends ContentResolverAnimatedViewContainer
{
public static final String IMAGE_NAME = Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera";
public static final String IMAGE_ID = getBucketId(CAMERA_IMAGE_BUCKET_NAME);
public static String getBucketId(String path)
{
return String.valueOf(path.toLowerCase().hashCode()); }
static Context cc;
String cp;
int picheight;
public PhotoExample(final Context context) {
super(context, 9);
cc = context;
picheight = getResources().getDimensionPixelSize(R.dimen.photo_example_height);
final String[] projection = { Images.Media.DATA };
final String selection = Images.Media.BUCKET_ID + " = ?";
final String[] selectionArgs = { IMAGE_ID };
createContentResolverLoop(Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null); }
@Override
public void onCreateData(ContentResolver contentResolver, Cursor dataCursor) {
final int column_data = dataCursor.getColumnIndexOrThrow(Images.Media.DATA);
cp = dataCursor.getString(column_data); }
@Override
public void onCreateViewContent(LayoutInflater layoutInflater, ViewGroup parentGroup, View[] containerViews, int index) {
containerViews[index] = layoutInflater.inflate(R.layout.example_photo, parentGroup, false);
ImageView photoView = (ImageView)containerViews[index].findViewById(R.id.photo);
photoView.setImageBitmap(decodeSampledBitmapFromFile(cp, 0, picheight)); }
public static Bitmap decodeSampledBitmapFromFile(String path, int Width, int Height) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
options.Size = calculateInSampleSize(options, Width, Height);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);}
public static int calculateInSampleSize(BitmapFactory.Options options, int Width, int Height) {
final int height = options.outHeight;
final int width = options.outWidth;
int Size = 1;
if (height > reqHeight || width > reqWidth) {
final int height_half = height/2;
final int width_half = width/2;
while ((height_half/Size) > Height && (width_half/Size) > Width) {
Size = Size * 2;
} }
return Size;
}
@Override
public void cleanup() { }
}
任何想法,我應該如何實現?
謝謝。
這些可以在上面類本身來實現,或者我需要另一個活動? – Thomas
您可以將它們添加到當前課程中。這些通常是自定義視圖,通常取代你的ImageView。查看每個庫的文檔以獲取更具體的信息。 –
謝謝。我會看到每個圖書館的文檔。 – Thomas