<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:animateLayoutChanges="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
//here put the view which is always visible
<LinearLayout
android:layout_width="match_parent"
android:visibilty="gone"
android:id="@+id/expandableLayout"
android:layout_height="wrap_content">
//here put which will collapse and expand
</LinearLayout>
</android.support.v7.widget.CardView>
podjąć logiczną isexpanded w ciebie ArrayList klasy obiektów
if (listobj.isexpanded)
{
holder.expandableLayout.setVisibility(View.VISIBLE);
}
else {
holder.expandableLayout.setVisibility(View.GONE);
}
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listobj.isexpanded)
{
holder.expandableLayout.setVisibility(View.GONE);
listobj.isexpanded=false;
notifyItemChanged(position);
}
else {
holder.expandableLayout.setVisibility(View.VISIBLE);
listobj.isexpanded=true;
notifyItemChanged(position);
}
}
});
spróbować cos takiego jak ten
Istnieją dwie części na widok karty, górna część, która zawsze będzie pokazywana, i dolna część, która będzie ukryta lub pokazana, prawda? Następnie możesz zmienić widoczność dolnej części każdej dotknięcia karty (lub dowolnego innego zdarzenia) i ustawić wysokość widoku karty 'wrap_content'. Jeśli działa to zgodnie z twoim intencją, możesz z łatwością uczynić to animacją, używając '' i '' w pliku xml wewnątrz twojego folderu 'anim'. Czy o to prosisz? Jeśli tak, daj mi znać, opublikuję kod. –
NecipAllef