android 边框重叠,android - Android:recyclerview中的viewitems轮廓与recyclerview边框重叠 - 堆栈内存溢出...

在我当前的项目中,我有一个RecyclerView ,其边框为圆角矩形。 我在布局xml中使用background view标签对其进行了设置,并产生了正确的效果:

...

android:background="@drawable/layout_sample_view_background"

....

/>

aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS93NzdVei5wbmc=

当我用longclick()视图项之一并使用ActionMode.Callback2打开浮动操作模式菜单时, ActionMode.Callback2 。 此选择与我的RecyclerView的边界重叠:

aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS94a2RBbC5wbmc=

顺便提一句。 不确定这是否重要,但是我的RecyclerView / ListAdapter中的viewitems使用的是自定义视图:

/**

* Custom view for each [RecyclerView] list item in the list inside a [SampleView]

*/

class SampleListItem(context: Context, attrs: AttributeSet, @AttrRes defStyleAttr: Int) : ConstraintLayout(context, attrs, defStyleAttr), View.OnLongClickListener {

constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)

init {

setOnLongClickListener(this)

clipToOutline = false

}

private val binding: LayoutSampleListItemBinding = LayoutSampleListItemBinding.inflate(LayoutInflater.from(context), this)

var sample: Sample? = null

set(value) {

field = value

fun Long.toTimeString(): String {

val date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(this), ZoneId.systemDefault())

val formatter = DateTimeFormatter.ofPattern("HH:mm")

val time = date.format(formatter)

Timber.d("With $this time was: $time")

return time

}

checkNotNull(value)

binding.id.text = value.sampleNumber.toString()

binding.timestamp.text = value.sampleTime.toTimeString()

binding.comment.text = SpannableStringBuilder(value.comment)

}

private var sampleItemClickListener = object : SampleItemClickListener {

override fun onSampleEditClick(sample: Sample) {

Timber.d("ActionMode edit icon clicked. Please edit $sample")

isSelected = !isSelected

}

override fun onSampleDeleteClick(sample: Sample) {

Timber.d("ActionMode delete icon clicked. Please delete $sample")

isSelected = !isSelected

}

}

interface SampleItemClickListener {

fun onSampleEditClick(sample: Sample)

fun onSampleDeleteClick(sample: Sample)

}

override fun onLongClick(v: View?): Boolean {

Toast.makeText(context,"longClick $sample", Toast.LENGTH_LONG).show()

// Start floating ActionMode

isSelected = true

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

val floatingActionModeCallback = SampleViewItemActionModeCallback(this, sampleItemClickListener, R.menu.sampleviewitem_menu_actions)

}

return true

}

}

我使用以下可绘制对象设置了此自定义视图的波纹效果:

android:color="@color/colorPrimaryLight">

android:id="@android:id/mask"

android:drawable="@color/icon_inactive_light_background" />

自定义视图的布局:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="wrap_content"

tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">

android:id="@+id/id"

style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:textAlignment="center"

app:layout_constraintEnd_toStartOf="@+id/timestamp"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="@+id/comment"

app:layout_constraintWidth_percent="0.10"

tools:text="@sample/samples.json/data/sampleId" />

android:id="@+id/timestamp"

style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:textAlignment="center"

app:layout_constraintEnd_toStartOf="@+id/comment"

app:layout_constraintStart_toEndOf="@+id/id"

app:layout_constraintTop_toTopOf="@+id/comment"

app:layout_constraintWidth_percent="0.20"

tools:text="@sample/samples.json/data/timestamp" />

android:id="@+id/comment"

style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"

android:layout_width="0dp"

android:layout_height="wrap_content"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toStartOf="@id/sampleviewitem_optional_icon"

app:layout_constraintStart_toEndOf="@id/timestamp"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintWidth_percent="0.60"

tools:hint="Kommentar"

tools:text="@sample/samples.json/data/comment" />

android:id="@+id/sampleviewitem_optional_icon"

style="@style/IconOnlyButton"

android:layout_width="0dp"

android:layout_height="0dp"

app:icon="@drawable/ic_edit_white_24dp"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintStart_toEndOf="@+id/layout_sample_item_sample_comment"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintWidth_percent="0.10" />

有谁知道造成这种影响的原因以及如何避免这种行为? 我知道ViewOutlineProvider ,但是我并不熟悉。 能解决这个问题吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值