91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

ScrollView實現圖片滑動功能

發布時間:2020-08-10 15:14:33 來源:網絡 閱讀:390 作者:uxlwsfmf 欄目:開發技術
public class MyScrollView_1Activity extends Activity {
    int[] ids = new int[] { R.drawable.a1, R.drawable.a3,
            R.drawable.a4, R.drawable.a5};
    private MyScrollView scrollView;
    private Context ctx;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.main);
        ctx = this;
        scrollView = new MyScrollView(this);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, -1);
        for (int i = 0; i < ids.length; i++) {
            ImageView iv = new ImageView(this);
            iv.setBackgroundResource(ids[i]);
            scrollView.addView(iv, params);
        }
        setContentView(scrollView);
    }
}
public class MyScrollView extends ViewGroup {
    private GestureDetector detector;
    private MyScrollView_1Activity ctx;
    private Scroller scroller;
    public MyScrollView(Context context) {
        super(context);
        this.ctx = (MyScrollView_1Activity) context;
        initView();
    }
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        for (int i = 0; i < getChildCount(); i++) {
            View view = getChildAt(i);
            view.layout(1 + i * getWidth(), t, r + i * getWidth(), b);
        }
    }
    private void initView() {
        scroller = new Scroller(ctx);
        detector = new GestureDetector(new OnGestureListener() {
            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                // TODO Auto-generated method stub
                return false;
            }
            @Override
            public void onShowPress(MotionEvent e) {
                // TODO Auto-generated method stub
            }
            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2,
                    float distanceX, float distanceY) {
                scrollBy((int) distanceX, 0);
                return false;
            }
            @Override
            public void onLongPress(MotionEvent e) {
                // TODO Auto-generated method stub
            }
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2,
                    float velocityX, float velocityY) {
                // TODO Auto-generated method stub
                return false;
            }
            @Override
            public boolean onDown(MotionEvent e) {
                // TODO Auto-generated method stub
                return false;
            }
        });
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        detector.onTouchEvent(event);
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            break;
        case MotionEvent.ACTION_MOVE:
            break;
        case MotionEvent.ACTION_UP:
            moveToDest();
            break;
        }
        return true;
    }
    public void moveToDest() {
        int dest = (getScrollX() + getWidth() / 2) / getWidth();
        moveToDest(dest);
    }
    private void moveToDest(int dest) {
        int distance = dest * getWidth() - getScrollX();
        scroller.startScroll(getScrollX(), 0, distance, 0);
        invalidate();
    }
    @Override
    public void computeScroll() {
        if (scroller.computeScrollOffset()) {
            scrollTo(scroller.getCurrX(), 0);
            postInvalidate();
        }
    }
}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

什邡市| 光泽县| 陵川县| 长泰县| 萍乡市| 仁布县| 长海县| 三门县| 新化县| 临洮县| 林口县| 云梦县| 壤塘县| 肇州县| 景谷| 柳州市| 遂溪县| 平和县| 昭苏县| 抚州市| 拉萨市| 融水| 白城市| 塔城市| 翁牛特旗| 共和县| 威宁| 长垣县| 兴仁县| 平武县| 广东省| 长汀县| 长海县| 赞皇县| 汾西县| 临汾市| 榆中县| 司法| 共和县| 南皮县| 延边|