从ViewPager触摸时如何显示全屏图像? **我使用Glide从网址中获取图片。
我试图使用FullScreenActivity并发送了imageUrls,但是我无法通过ImagePagerAdapter.java中的InstantiateItem方法启动startActivity()。
ImagePagerAdapter.java
public class ImagePagerAdapter extends PagerAdapter {
private Context mContext;
private String[] imageUrls;
public ImagePagerAdapter(Context mContext, String[] imageUrls) {
this.mContext = mContext;
this.imageUrls = imageUrls;
}
@Override
public int getCount() {
return imageUrls.length;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return view == o;
}
@NonNull
@Override
public Object instantiateItem(@NonNull final ViewGroup container, final int position) {
final ImageView imageView = new ImageView(mContext);
Glide.with(mContext)
.load(imageUrls[position])
.into(imageView);
container.addView(imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Display full screen images when touched.
}
});
return imageView;
}
}
LocalExperienceDetail.java
public class LocalExperienceDetail extends AppCompatActivity {
private String[] imageUrls;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_local_experience_detail);
String company_name_eng = getIntent().getExtras().getString("name_eng");
String img1 = getIntent().getExtras().getString("img1");
String img2 = getIntent().getExtras().getString("img2");
String img3 = getIntent().getExtras().getString("img3");
String img4 = getIntent().getExtras().getString("img4");
String img5 = getIntent().getExtras().getString("img5");
String description_activity = getIntent().getExtras().getString("activity");
String time = getIntent().getExtras().getString("time");
String price = getIntent().getExtras().getString("price");
String tel = getIntent().getExtras().getString("tel");
String car_park = getIntent().getExtras().getString("car_park");
String address = getIntent().getExtras().getString("address");
String website = getIntent().getExtras().getString("website");
TextView tvCompanyNameEng = findViewById(R.id.txtCompanyName);
TextView tvDescActivity = findViewById(R.id.txtDescActivity);
TextView tvPrice = findViewById(R.id.txtPrice);
TextView tvTel = findViewById(R.id.txtTel);
TextView tvCarPark = findViewById(R.id.txtCarPark);
TextView tvAddress = findViewById(R.id.txtAddress);
TextView tvWebsite = findViewById(R.id.txtWebsite);
TextView tvTime = findViewById(R.id.txtTime);
ViewPager viewPager = findViewById(R.id.imgView);
tvCompanyNameEng.setText(company_name_eng);
tvDescActivity.setText(description_activity);
tvPrice.setText(price);
tvTel.setText(tel);
tvCarPark.setText(car_park);
tvAddress.setText(address);
tvWebsite.setText(website);
tvTime.setText(time);
imageUrls = new String[] {
img1,
img2,
img3,
img4,
img5
};
ImagePagerAdapter adapter = new ImagePagerAdapter(this, imageUrls);
viewPager.setAdapter(adapter);
}
}
我希望全屏图像可以滑动。
答案 0 :(得分:0)
有可能。方法startActivity是上下文类(doc)
的方法成员 imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Display full screen images when touched.
Intent intent = new Intent(); // Your intent
mContext.startActivity(intent);
}
});
如果您需要使用图像(例如画廊),facebook可以开发Fresco库。看看。