2016-03-30 18 views
2
Schiebe

Ich verwende SlidingUpPanelLayout und ich möchte von den weißen Layout, Farbe ändern mit diesem Code zu #4096c3 wenn SlidingUpPanelLayout nach oben schieben (float slideOffset ist zwischen 0,0-1,0):Glatter Farbwechsel, wenn

SlidingUpPanelLayout.PanelSlideListener onslide = new SlidingUpPanelLayout.PanelSlideListener() { 
    @Override 
    public void onPanelSlide(View panel, float slideOffset) { 
     backcolor = android.graphics.Color.argb(Math.round(255 * slideOffset), 64, 150, 195); 
     panel_layout.setBackgroundColor(backcolor); 
    } 

    @Override 
    public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) { 

    } 
}; 

Was ist falsch mit diesem Code, denn wenn ich rutschen plötzlich ändert sich von weiß zu #4096c3?

Antwort

0

Ihre LinearLayout(Header) Referenz: -

LinearLayout mTitleLinearLayout= (LinearLayout) findViewById(R.id.llyout_header); 

Ihre SlidingUpPanelLayout Referenz: -

SlidingUpPanelLayout mLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout); 

Ihre Zuhörer: -

mLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() { 

     @Override 
     public void onPanelSlide(View panel, float slideOffset) { 

      Log.i(TAG, "onPanelSlide, offset " + slideOffset); 

      //Here is the code which change titleBar color gradually 
      mTitleLinearLayout.setBackgroundColor((int) new ArgbEvaluator().evaluate(slideOffset, Color.parseColor("#03A9F4"), Color.parseColor("#F44336"))); 


     } 

     @Override 
     public void onPanelStateChanged(View panel, PanelState previousState, PanelState newState) { 



     } 

     // During the transition of expand and collapse onPanelSlide function will be called. 

    });