我需要安卓中自定义手风琴视图的参考.



我正在做一个需要安卓自定义手风琴视图的项目.如果有人按照这种要求工作,请告诉我。提前谢谢。

这是我

的代码

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();
    }

}

请尝试此链接,这可能会有所帮助https://github.com/hamsterready/android-accordion-view

最新更新