2015-04-24 74 views
0

中定製手風琴視圖的參考我正在研究一個需要android中的自定義手風琴視圖的項目。如果有人從事這樣的需求,那麼請讓我知道。提前致謝。我需要在android

回答

0

這是我的代碼

public class AccordianView extends LinearLayout implements View.OnClickListener { 
    private final TextView headerText; 
    private final LinearLayout llChildAcoradian; 
    private final Context context; 
    private boolean isOpen = false; 
    private static final int ANIM_DURATION_FOR_ACCORDIAN = 500; 


    public AccordianView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     this.context = context; 
     setClickable(true); 
     setFocusable(true); 
     TypedArray a = context.obtainStyledAttributes(attrs, 
       R.styleable.AccordianView, 0, 0); 
     String titleText = a.getString(R.styleable.AccordianView_accor_header_text); 
     float textSize = a.getFloat(R.styleable.AccordianView_accor_header_text_size, 16.0f); 
     a.recycle(); 

     setOrientation(LinearLayout.VERTICAL); 
     setGravity(Gravity.CENTER_VERTICAL); 

     LayoutInflater inflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     inflater.inflate(R.layout.layout_accordian, this, true); 

     headerText = (TextView) getChildAt(0); 
     headerText.setText(titleText); 
     headerText.setTextSize(textSize); 
     headerText.setOnClickListener(this); 

     llChildAcoradian = (LinearLayout) getChildAt(1); 

     headerText.setText("Now :" + (llChildAcoradian.getVisibility() == View 
       .VISIBLE ? "Open" : "Closed")); 
     llChildAcoradian.setVisibility(View.VISIBLE); 


    } 

    @Override 
    public void onClick(View v) { 

     ExpandAndCollapseAnimation expandAni = new ExpandAndCollapseAnimation(llChildAcoradian, ANIM_DURATION_FOR_ACCORDIAN); 
     llChildAcoradian.startAnimation(expandAni); 
    } 


    public void toggleViewState() 
    { 
     headerText.performClick(); 
    } 



}