scrollview滾動到指定位置

妖怪都是妖怪發表於2018-01-11
private Runnable runnableYeMian = new Runnable() {

    @Override
    public void run() {
        // 獲取元件到頂部的高度
        mXunHuanBiaoGeGeShu = mTiaoZhuanXianShiLinearLayout.getTop();

        // 獲取螢幕高度
        WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        mXunHuanBiaoGeGeShu = mXunHuanBiaoGeGeShu+(display.getHeight()/2);

        Log.i("巡店","滑動距離:"+mXunHuanBiaoGeGeShu);

        mscrollView.scrollTo(0, mXunHuanBiaoGeGeShu);// 改變滾動條的位置

        Log.i("巡店","滑動");
    }
};

/**
 * 跳轉頁面指定位置 smoothScrollTo
 */
public void TiaoZhuanYeMianZhiDingWeiZhi(){

    Handler handler = new Handler();
    handler.postDelayed(runnableYeMian, 0);
    Log.i("巡店","滑動呼叫");
    mIsTiaoZhuanWeiZhi = false;

}

相關文章