我打算在用户开始拖动时增加单元格的高度,并在用户删除时降低高程。拖动开始时,由于高程引起的阴影被剪裁。任何想法如何解决它?
我曾尝试在recyclerview上添加clipChildren = false
和clipToPadding = false
,但没有任何区别。使用cardView.setCardElevation
设置代码中的高程。有什么想法吗?
RecyclerView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/blrtMediaSelector_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:scrollbars="vertical" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/blrtMediaSelector_addBtn"
app:layout_behavior="blrtapp.droid.mediaPicker.AddButtonBehaviour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="16dp"
app:fabSize="normal"
android:src="@drawable/ic_plus" />
</android.support.design.widget.CoordinatorLayout>
细胞:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mediaSelectorCell_cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="2dp"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true">
<RelativeLayout
android:id="@+id/mediaSelectorCell_parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:background="@color/white">
<!-- thumbnail -->
<ImageView
android:id="@+id/mediaSelectorCell_thumbnail"
android:layout_width="@dimen/blrtMediaSelectorCell_size"
android:layout_height="@dimen/blrtMediaSelectorCell_size"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="@drawable/splash" />
<!-- select icon -->
<ImageView
android:id="@+id/mediaSelectorCell_selectIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@id/mediaSelectorCell_thumbnail"
android:layout_alignBottom="@id/mediaSelectorCell_thumbnail"
android:layout_marginEnd="2dp"
android:layout_marginBottom="2dp" />
<!-- container for text fields -->
<LinearLayout
android:id="@+id/mediaSelectorCell_textContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/mediaSelectorCell_thumbnail"
android:paddingStart="6dp"
android:paddingEnd="2dp"
android:orientation="vertical">
<!-- primary text -->
<TextView
android:id="@+id/mediaSelectorCell_primaryTex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/charcoal"
android:ellipsize="end"
android:maxLines="1"
android:text="Primary text"
android:textSize="14sp" />
<!-- secondary text -->
<TextView
android:id="@+id/mediaSelectorCell_secondaryText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/gray4"
android:text="secondary text"
android:textSize="12sp" />
</LinearLayout>
<!-- anchor to drag the cell -->
<ImageButton
android:id="@+id/mediaSelectorCell_dragAnchorButton"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="8dp"
android:scaleType="center"
android:background="@color/white"
android:src="@drawable/media_drag"
android:layout_centerVertical="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
请不要认为这只是为了满足最低细节的要求,因为代码不仅仅是文字
答案 0 :(得分:1)
也添加
cardView.setOutlineProvider(android.view.ViewOutlineProvider.BOUNDS);
cardView.setClipToOutline(false);
这对我有用,可以在RecyclerView中生成阴影。
答案 1 :(得分:0)
如果按钮位于父母的底部,
父ViewGroup
也可能正在剪切阴影。
确保父级有填充并在父级
上设置android:clipToPadding="false"