我通过更改可扩展卡视图的可见性,在android Studio中创建了可扩展和可折叠卡视图。(因此,如果可见,则已展开,如果不可见,则折叠,每个卡片视图都有一个状态,即是展开还是折叠。)
但当一个卡片视图展开时,它就位于下一个卡片视图的下方。有什么方法可以将折叠的卡片视图推离扩展的卡片视图?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp" --> the extra 100dp for the expanded view
android:orientation="vertical"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_marginBottom="-100dp"> --> this allows the card views to be underneath each other when not expanded
....
</LinearLayout>
卡视图适配器中的我的代码。。。
private void onClickButton(final CardView expandableLayout, final
LinearLayout mainlayout, final int i){
if (expandableLayout.getVisibility() == View.VISIBLE){
expandableLayout.setVisibility(View.GONE);
expandState.put(i,false);
}
else{
expandableLayout.setVisibility(View.VISIBLE);
// ideally mainlayout.
// something to change the android:layout_marginBottom="0" ?
expandState.put(i,true);
}
}
我想我需要实现一些代码来更改主布局参数,当它可见时,当它不可见时,我就是找不到要使用的代码。