首先,我很抱歉我的问题名称。现在我说你有什么问题。我有一个片段,有一个imageView和2个按钮(上一个和下一个)。所以在那个imageView我添加了第一张图片来自画廊。然后点击下一步我想看到画廊的下一张图片。我已经获得的图像路径。
让我告诉你代码。
public class PhotoFragment extends BaseFragment{
View mainView;
private ImageView photoView;
private Button prev, next;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mainView = inflater.inflate(R.layout.photo_fragment, container, false);
photoView = (ImageView) mainView.findViewById(R.id.photoView);
prev = (Button) mainView.findViewById(R.id.prevPhoto);
next = (Button) mainView.findViewById(R.id.nextPhoto);
getAllShownImagesPath(getActivity());
return mainView;
}
ArrayList<String> getAllShownImagesPath(Activity activity) {
Uri uri;
Cursor cursor;
int column_index_data;
final ArrayList<String> listOfAllImages = new ArrayList<>();
String absolutePathOfImage;
uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.MediaColumns.DATA,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
cursor = activity.getContentResolver().query(uri, projection, null,
null, null);
column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
while (cursor.moveToNext()) {
absolutePathOfImage = cursor.getString(column_index_data);
listOfAllImages.add(absolutePathOfImage);
}
Bitmap myBitmap = BitmapFactory.decodeFile(listOfAllImages.get(0));
photoView.setImageBitmap(myBitmap);
photoView.setRotation(90);
Bitmap myBitmap1 = BitmapFactory.decodeFile(listOfAllImages.get(1));
Bitmap myBitmap2 = BitmapFactory.decodeFile(listOfAllImages.get(2));
Bitmap myBitmap3 = BitmapFactory.decodeFile(listOfAllImages.get(3));
Bitmap myBitmap4 = BitmapFactory.decodeFile(listOfAllImages.get(4));
Bitmap myBitmap5 = BitmapFactory.decodeFile(listOfAllImages.get(5));
Bitmap myBitmap6 = BitmapFactory.decodeFile(listOfAllImages.get(6));
final ArrayList<Bitmap> bitmap = new ArrayList<>();
bitmap.add(myBitmap);
bitmap.add(myBitmap1);
bitmap.add(myBitmap2);
bitmap.add(myBitmap3);
bitmap.add(myBitmap4);
bitmap.add(myBitmap5);
bitmap.add(myBitmap6);
prev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
cursor.close();
return listOfAllImages;
}
你在这里看到我正在获取第一张图片并在imageView中设置它。
Bitmap myBitmap = BitmapFactory.decodeFile(listOfAllImages.get(0));
photoView.setImageBitmap(myBitmap);
但我不能做滑动部分。我怎样才能做到这一点?感谢。
答案 0 :(得分:1)
function testX(x){
return x ? x : 1;
}
// Truthy:
console.log(testX(10)); // 10
console.log(testX({})); // {}
console.log(testX(true)); // true
console.log(testX("something")); // "something"
// Falsy:
console.log(testX("")); // 1
console.log(testX()); // 1
console.log(testX(4-"Z")); // 1 because 4-"Z" == NaN
console.log(testX(false)); // 1
console.log(testX(0)); // 1
console.log(testX(null)); // 1