3
我盡我的主滾動型的滾動事件過程中創建我的動作條淡入阿爾法:更改動作條阿爾法滾動事件期間
我嘗試這樣做:
//Active Overlay for ActionBar before set my content in the activity
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
//create a new Drawable for the AB background
final ColorDrawable newColor = new ColorDrawable(getResources().getColor(R.color.primaryColor));
newColor.setAlpha(0);
getActionBar().setBackgroundDrawable(newColor);
//create a OnScrollListener to get ScrollY position
final ScrollView mainScrollView = (ScrollView) findViewById(R.id.place_detail_scrollView);
mainScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
final int scrollY = mainScrollView.getScrollY();
final int boundY = 300;
final float ratio = (float) (scrollY/boundY) ;
newColor.setAlpha((int)(ratio*255));
}
});
從理論上講,我的動作條會褪色它在ScrollView的位置0和300之間的阿爾法。不幸的是,我的AB每次都是透明的......任何想法?