图像平滑滚动
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_viewer); if (savedInstanceState != null) { isDialogShowing = savedInstanceState.getBoolean(DIALOG_STATE_KEY, false); } sharedPreferences = getSharedPreferences(KEY.PREFS_NAME, MODE_PRIVATE); if (sharedPreferences.getBoolean(KEY.KEY_BRIGHTNESS, false)) { setBrightnessToMax(); } photoButtonBar = findViewById(R.id.photo_button_bar); imageView = findViewById(R.id.image_view); backButton = findViewById(R.id.imageback); backButton.setOnClickListener(v -> finish()); // Initialize GestureDetector and set onTouchListener for the imageView gestureDetector = new GestureDetector(this, new SwipeGestureDetector()); imageView.setOnTouchListener((v, event) -> gestureDetector.onTouchEvent(event)); // Retrieve the list of media paths from the Intent mediaPaths2 = getIntent().getStringArrayListExtra("MEDIA_PATHS"); if (mediaPaths2 == null || mediaPaths2.isEmpty()) { Toast.makeText(this, "No media paths provided", Toast.LENGTH_SHORT).show(); finish(); return; } // Get the current media file path mediaPath = getIntent().getStringExtra("MEDIA_PATH"); if (mediaPath != null) { currentIndex = mediaPaths2.indexOf(mediaPath); if (currentIndex == -1) { Toast.makeText(this, "Media path not found in list", Toast.LENGTH_SHORT).show(); finish(); return; } } else { Toast.makeText(this, "Media path not provided", Toast.LENGTH_SHORT).show(); finish(); return; } // Continue with loading the image mediaUri = getMediaUri(mediaPath); if (mediaUri == null) { Toast.makeText(this, "Media file not found", Toast.LENGTH_SHORT).show(); finish(); return; } // Load the image using the mediaUri imageView.setImageURI(mediaUri); }
内容来源: davemorrissey/subsampling-scale-image-view