我正在开发一个需要在android中定制手风琴视图的项目。如果有人按此类要求工作,请告诉我。提前谢谢。
答案 0 :(得分:1)
这是我的代码
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();
}
}
答案 1 :(得分:0)
请尝试此链接,这可能有所帮助 https://github.com/hamsterready/android-accordion-view