小编Sum*_*nan的帖子

18
推荐指数
2
解决办法
8444
查看次数

如何在jetpack compose中将Surface中的项目居中

如何在jet pack compose中将项目置于表面中心

@Composable
fun RoundedShapeWithIconCenter(
    modifier: Modifier = Modifier,
    parentSize : Dp,
    parentBackgroundColor : Color,
    childPadding : Dp,
    icon : Painter,
    iconSize : Dp,
    iconTint : Color,
    elevation : Dp = 0.dp,
    isTextOrIcon : Boolean = false,
    insideText : String = "",
    insideTextColor : Color = colorResource(id = R.color.black),
    fontSize: TextUnit = 16.sp
) {
    Surface(
        modifier = modifier.size(parentSize),
        shape = RoundedCornerShape(50),
        color = parentBackgroundColor,
        elevation = elevation,
    ) {
        if (isTextOrIcon) {
            CommonText(value = insideText, fontSize = fontSize, …
Run Code Online (Sandbox Code Playgroud)

android center surface android-jetpack-compose

8
推荐指数
1
解决办法
6880
查看次数

列表适配器 Diff Util 不更新 Recyclerview 中的列表项

列表适配器 diffutil 未更新 recyclerview 中的列表项。

当我从列表中添加或删除项目时它会起作用。isSelected : Boolean = false但不会像对象类中那样更新任何特定值

当列表中的对象类之一发生更改(例如一个对象类中的布尔值更改)时,如何更新 recyclerview 视图

谢谢

下面的适配器类

class CategoryMainAdapter(
    var itemClick : CategoryItemClick,
    var screenWidth : Int = 0
) : ListAdapter<CategoryModel, CategoryMainAdapter.CategoryMainViewHolder>(CategoryMainDiffUtils()) {

    inner class CategoryMainViewHolder(val binding : CategorySingleListLayoutBinding) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryMainViewHolder {
        val binding = CategorySingleListLayoutBinding.inflate(LayoutInflater.from
            (parent.context),
            parent,
            false
        )
        return CategoryMainViewHolder(binding)
    }

    override fun onBindViewHolder(holder: CategoryMainViewHolder, position: Int) {
        val model = getItem(position)
        holder.apply {
            binding.apply {
                mainLinearLayout.layoutParams.apply {
                    width = …
Run Code Online (Sandbox Code Playgroud)

android listadapter kotlin android-recyclerview android-diffutils

8
推荐指数
1
解决办法
6464
查看次数