我的应用程序提供了许多图像,因此我通过按钮(i10)从一个图像移动到流动图像,然后向后移动我使用另一个按钮(i8)。 我认为这种方法有点陈旧,我想在图像之间进行SWIPE,但我真的不知道,我读了许多关于刷卡但没有成功。 这是我的旧时尚代码:
num = 1;
imagename = getIntent().getExtras().getString("somekey");
resId = getApplicationContext().getResources().getIdentifier(
imagename + num, "drawable", getPackageName());
image1.setImageResource(resId);
num++;
i10.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
resId = getApplicationContext().getResources()
.getIdentifier(imagename + num, "drawable",
getPackageName());
} catch (NotFoundException e) {
e.printStackTrace();
}
if (resId > 0) {
image1.setImageResource(resId);
num++;
overridePendingTransition(R.anim.pushin, R.anim.pushout);
} else {
Intent i = new Intent(getApplicationContext(), Menu.class);
startActivity(i);
overridePendingTransition(R.anim.pushinhorizontal,
R.anim.pushouthorizontal);
}
}
});
i8.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
num = num - 2;
try {
resId = getApplicationContext().getResources()
.getIdentifier(imagename + num, "drawable",
getPackageName());
} catch (NotFoundException e) {
e.printStackTrace();
}
if (resId > 0) {
image1.setImageResource(resId);
num++;
overridePendingTransition(R.anim.pushin, R.anim.pushout);
} else {
Intent i = new Intent(getApplicationContext(), Menu.class);
startActivity(i);
overridePendingTransition(R.anim.pushinhorizontal,
R.anim.pushouthorizontal);
}
}
});