开发者

android gallery horizontal scrolling. Help please

开发者 https://www.devze.com 2023-03-28 14:42 出处:网络
I have a gallery with images and when scroll horizontally, multiple images are scrolled instead of one. please help me solve this

I have a gallery with images and when scroll horizontally, multiple images are scrolled instead of one. please help me solve this Below is part of my code. thanks in advance

public View getView(int position, View convertView, ViewGroup parent) {

        View view = convertView;
        if (convertView == null) {
            view = inflater.inflate(resourceid, null);
        }
        synchronized (view) {
            TextView txtTitle = (TextView) view
                    .findViewById(R.id.txtCaption);
            ImageList item = getItem(position);

            ImageView ivImage = (ImageView) view.findViewById开发者_如何学运维(R.id.ivImage);
            ivImage.setScaleType(ScaleType.CENTER_INSIDE);

            try {
                ivImage.setImageBitmap(getBitmapFromAsset(item.imageUrl));

}


This solution works perfectly.

PS: You need to extends a Gallery.

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    int kEvent =
            e1.getX() < e2.getX() ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT;
    onKeyDown(kEvent, null);
    return true;
}


for that you have create custom gallery you can refer the example here

to slow down fast navigation of your gallery try below code

yourGallery.setCallbackDuringFling(false);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号