我有一个ListView。当点击一行时,一些按钮的可见性在可见和消失之间切换。但我发现无论出现多少个按钮, ListView的高度都保持不变。行高确实会发生变化。你能告诉我如何更新/刷新ListView吗? RelativeLayout用于包含ListView的Activity布局和包含按钮的Adapter布局。
> listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
> public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
> View toolbarView = view.findViewById(R.id.toolbar);
> toolbarView.requestLayout();
> RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) toolbarView.getLayoutParams();
> if(toolbarView.getVisibility() == View.VISIBLE){
> toolbarView.setVisibility(View.GONE);
> layoutParams.bottomMargin = 0 - toolbarView.getHeight();
>
> }
> else{
> toolbarView.setVisibility(View.VISIBLE);
> layoutParams.bottomMargin = 0;
>
> }
> toolbarView.requestLayout();
> }
> });
的ListView:
<ListView android:id="@+id/list_collections" android:layout_width="fill_parent" android:layout_height="wrap_content" android:divider="@color/list_divider" android:listSelector="@drawable/list_row_selector" android:background="#13ff3f" android:dividerHeight="1dp"/>
适配器布局
<TextView android:id="@+id/book_title" android:text="XXXXXX" android:textSize="@dimen/book_title_size" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="2dip" android:layout_marginLeft="4dip" android:layout_row="0" android:layout_column="0" android:textStyle="bold" android:layout_gravity="left"/> <TextView android:id="@+id/book_latest_chapter" android:text="XXXX" android:layout_row="1" android:layout_column="0" android:layout_columnSpan="2" android:layout_marginLeft="4dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/book_title" android:layout_gravity="left"/> <ImageView android:id="@+id/book_actions" android:layout_marginLeft="4dip" android:src="@drawable/arrow_down_grey" android:layout_height="wrap_content" android:layout_width="wrap_content" android:clickable="true" android:layout_marginEnd="5dp" android:layout_alignParentRight="true" android:layout_below="@+id/book_title" /> <RelativeLayout android:id="@+id/toolbar" android:layout_marginBottom="0dp" android:visibility="visible" android:layout_height="wrap_content" android:layout_below="@+id/book_progress" android:layout_width="fill_parent"> <TextView android:id="@+id/book_action_remove" android:text="XX" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@color/color_white" android:background="@drawable/button_background" android:drawableLeft="@drawable/delete" android:layout_margin="5dip" android:gravity="center"/> <TextView android:id="@+id/book_action_toc" android:text="XXX" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@color/color_white" android:background="@drawable/button_background" android:layout_toRightOf="@+id/book_action_remove" android:drawableLeft="@drawable/toc" android:layout_margin="5dip" android:gravity="center"/> </RelativeLayout>