我正在使用@Chabbal的SlidingSplashScreen库在图像之间滑动,并在图像下方显示小点,以跟踪所显示的图像。并使用fullScreenActivity以全屏显示图像。我想全屏显示按下的图像,但是发生的情况是fullScreenActivity从第一个图像而不是我在其上按下的图像开始。这是我的代码
MainActivity.java
package com.hodhod.testproject;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.chabbal.slidingdotsplash.OnItemClickListener;
import com.chabbal.slidingdotsplash.SlidingSplashView;
public class MainActivity extends AppCompatActivity {
private int[] images = {
R.drawable.heart,
R.drawable.pexels,
R.drawable.download
};
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SlidingSplashView slidingSplashView = findViewById(R.id.sliding_splash_view);
slidingSplashView.setImageResources(images);
slidingSplashView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onPagerItemClick(View view, int position) {
Intent myIntent = new Intent(MainActivity.this, FullScreenActivity.class);
myIntent.putExtra("imagesId", images);
myIntent.putExtra("position", position);
startActivity(myIntent);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<com.chabbal.slidingdotsplash.SlidingSplashView
android:id="@+id/sliding_splash_view"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true">
</com.chabbal.slidingdotsplash.SlidingSplashView>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="150dp"
/>
</RelativeLayout>
FullScreenActivity.java
package com.hodhod.testproject;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.chabbal.slidingdotsplash.SlidingSplashView;
public class FullScreenActivity extends AppCompatActivity {
int[] imageId;
int position1;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullscreen);
final SlidingSplashView slidingSplashViewFull = findViewById(R.id.sliding_splash_view_full);
Intent myIntent = getIntent();
Bundle bundle = myIntent.getExtras();
if(bundle != null){
imageId = bundle.getIntArray("imagesId");
position1 = bundle.getInt("position");
if(position1 == 0){
Toast.makeText(getApplicationContext(), "image1", Toast.LENGTH_SHORT).show();
}
if(position1 == 1){
Toast.makeText(getApplicationContext(), "image2", Toast.LENGTH_SHORT).show();
}
if(position1 == 2){
Toast.makeText(getApplicationContext(), "image3", Toast.LENGTH_SHORT).show();
}
slidingSplashViewFull.setImageResources(imageId);
}
}
}
fullscreen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.chabbal.slidingdotsplash.SlidingSplashView
android:id="@+id/sliding_splash_view_full"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.chabbal.slidingdotsplash.SlidingSplashView>
</LinearLayout>