2016-04-22 48 views
0

如何將面板滑動到底部直到面板內部佈局達到屏幕底部。然後停止動畫。所有面板佈局都是動態高度。不得使用靜態值。 我使用:Android滑動LinearLayout直到內部達到底部

public void slideDown(Context context, LinearLayout ln){ 
     Animation slide_down = AnimationUtils.loadAnimation(context, R.anim.slide_down); 
     ln.startAnimation(slide_down); 
    } 

slideDown(getContext(), myLayout); 

回答

0

如果我正確理解你的問題,你要滑動的LinearLayout到屏幕的底部,並停止動畫時lineaLayout底部「觸摸「屏幕的底部。下面是我如何做到這一點:

public void slideDown (View movableView,View rootView){ 
    //rootView is the Layout placed as root in your xml 
    float screenBottom = rootView.getBottom()/2; //real bottom of the screen 
    float viewHeight = movableView.getHeight(); 
    movableView.animate().translationYBy(screenBottom - viewHeight).setDuration(1000).start(); 
} 
+0

不,在linearLayout中,我得到了另一個包含文本的佈局。當內部佈局底部觸摸屏幕底部時,我希望動畫停止 – TeodorKolev