我想从drawable逐个加载图像数组。在给定时间,ImageView应该在用户滑动时显示一个图像,它应该加载下一个图像。
我能实现这个吗?我不喜欢画廊视图,我直接需要加载单个图像数据填充屏幕并滑动直到数组结束。
提前感谢您的时间。
答案 0 :(得分:3)
查看ImageSwitcher。它应该符合您的需求。
答案 1 :(得分:2)
您可以将ViewFilpper
或ViewSwitcher
或ImageSwitcher
用于您的目的。所有这些类都扩展ViewAnimator
,因此它们具有非常相似的行为和功能,并且只在ViewAnimator
之上添加了一些有用的函数。
答案 2 :(得分:2)
我有一个不同的解决方案:
https://github.com/ysamlan/horizontalpager
这是一个可以添加孩子的ViewGroup,当向左或向右滑动时,您将在全屏显示下一个或上一个孩子。它也被编写,以便在您需要时可以实现垂直滚动。
答案 3 :(得分:0)
经过几个小时的思考,我想出了解决方案,因为没有一个答案对我有帮助。
Java代码
public class ImagePreviewActivity extends Activity implements OnClickListener {
public int currentimageindex=0;
private int[] IMAGE_IDS ={R.drawable.splash1, R.drawable.splash2, R.drawable.image_preview, R.drawable.report_incident_exclamation_mark};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.media_preview);
ImageView imageview = (ImageView)findViewById(R.id.ImageViewPreview);
imageview.setImageResource(R.drawable.splash1);
currentimageindex++;
imageview.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(500);
ImageView imageview = (ImageView)findViewById(R.id.ImageViewPreview);
imageview.startAnimation(inFromRight);
if ((IMAGE_IDS.length)> currentimageindex){
imageview.setImageResource(IMAGE_IDS[currentimageindex]);
currentimageindex++;
}
}
}