2016-03-18 21 views

回答

0

這可以通過設置向下和向上箭頭單擊視圖的可見性來實現。還應用動畫來提供展開和崩潰的感覺。

0

創建方法坍塌(集可視性消失)可見對於要在edittext.Following方法點擊展開視圖各方意見,然後只設置公開程度可以用來給它一個崩潰的感覺:

public static void expand(final View v) { 
    v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    final int targetHeight = v.getMeasuredHeight(); 

    // Older versions of android (pre API 21) cancel animations for views with a height of 0. 
    v.getLayoutParams().height = 1; 
    v.setVisibility(View.VISIBLE); 
    Animation a = new Animation() 
    { 
     @Override 
     protected void applyTransformation(float interpolatedTime, Transformation t) { 
      v.getLayoutParams().height = interpolatedTime == 1 
        ? LayoutParams.WRAP_CONTENT 
        : (int)(targetHeight * interpolatedTime); 
      v.requestLayout(); 
     } 

     @Override 
     public boolean willChangeBounds() { 
      return true; 
     } 
    }; 

    // 1dp/ms 
    a.setDuration((int)(targetHeight/v.getContext().getResources().getDisplayMetrics().density)); 
    v.startAnimation(a); 
} 

public static void collapse(final View v) { 
    final int initialHeight = v.getMeasuredHeight(); 

    Animation a = new Animation() 
    { 
     @Override 
     protected void applyTransformation(float interpolatedTime, Transformation t) { 
      if(interpolatedTime == 1){ 
       v.setVisibility(View.GONE); 
      }else{ 
       v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime); 
       v.requestLayout(); 
      } 
     } 

     @Override 
     public boolean willChangeBounds() { 
      return true; 
     } 
    }; 

    // 1dp/ms 
    a.setDuration((int)(initialHeight/v.getContext().getResources().getDisplayMetrics().density)); 
    v.startAnimation(a); 
}