我需要将imageView与textView的end对齐,两者都限制在end to a checkbox。我的代码的问题是imageView总是出现在textView的start of复选框中,而不是文本的结尾处。有人能帮上忙吗

<androidx.constraintlayout.widget.ConstraintLayout 
    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="0dp"
    android:layout_height="wrap_content"
    android:background="@color/white">

    <TextView
        android:id="@+id/tvMerchantTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/margin4"
        android:layout_marginEnd="@dimen/margin8"
        android:layout_marginStart="@dimen/margin16"
        android:drawablePadding="@dimen/padding4"
        android:ellipsize="middle"
        android:maxWidth="@dimen/width200"
        android:singleLine="true"
        android:textSize="@dimen/textSize12"
        app:layout_constraintBottom_toTopOf="@id/tvMerchantSubtitle"
        app:layout_constraintEnd_toStartOf="@id/cbMerchantSelect"
        app:layout_constraintHorizontal_bias="0"
        app:layout_constraintStart_toEndOf="@id/ivMerchantLogo"
        app:layout_constraintTop_toTopOf="@id/ivMerchantLogo" />

    <androidx.appcompat.widget.AppCompatCheckBox
        android:id="@+id/cbMerchantSelect"
        android:layout_width="@dimen/width16"
        android:layout_height="@dimen/height16"
        android:layout_marginEnd="@dimen/margin16"
        android:button="@drawable/ic_round_checkbox"
        android:clickable="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

我正在使用glide将图像设置为textView end drawable -

Glide.with(this)
                .load(url)
                .into(object : CustomTarget<Drawable?>(
                    DisplayUtils.dpToPx(this.context, R.dimen.width30),
                    DisplayUtils.dpToPx(this.context, R.dimen.height20)
                ) {

                    override fun onLoadCleared(@Nullable placeholder: Drawable?) {}

                    override fun onResourceReady(
                        resource: Drawable,
                        transition: com.bumptech.glide.request.transition.Transition<in Drawable?>?
                    ) {
                        mBinding.inPaymentMethod.tvMerchantTitle.setCompoundDrawablesWithIntrinsicBounds(
                            null,
                            null,
                            resource,
                            null
                        )
                    }
                })

转载请注明出处:http://www.zhongtian365.com/article/20230526/2055928.html

随机推荐

  1. 在TextView中以编程方式设置左可绘制

    我在xml中有一个textView。 TextView android:id="@+id/bookTitle" android:layout_width="match_parent" an...

  2. 如何在相对布局中将Textview放置在Imageview的右侧和中心

    我想把一个文本视图放在图像视图的右侧和重心。为此,我使用相对布局。使用相对布局,我可以将文本视图设置为图像view.But的右侧,但无法将其设置为中心。我的意思是这里的中心不在图像视图的内部,我想把文本视图放在图像视图的右中心(图像视图的外...

  3. 根据用户输入在GridView中将ImageView更改为TextView

    我正在开发一个android应用程序作为一个教育项目。我已经创建了一个使用自定义GridAdapter的GridView对象。默认情况下,网格加载一组占位符图像。我希望用户能够将这些占位符图像替换为自己的图像,一些文本,或到youtube视...

  4. 如何在event setOnItemClickListener中将TextView中的文本设置为GridView的项目

    我有自定义的TextView,在GridView有308个项目的TextView。我想在点击GridView的项目时设置文本,我在custom Adapter“的函数getView”中的event TextView setOnClickLi...

  5. 在TextView上工作时,setText on按钮不工作

    这是我的Firebase数据库结构:enter image description here我对Java还很陌生,正在尝试找出解决这个问题的方法。所以到目前为止,我正在制作一个测验应用程序,除了我不能从Firebase RealTime数据...

  6. 在Android TextView中将MySQL日期时间转换为特定格式

    我最近开始学习java和如何构建android应用程序。我目前正在开发一个应用程序,它使用CustomListAdapter来显示通过json解析成ListView的MySQL数据。我遇到的问题是如何更改TextView显示数据库中的日期时...

  7. 如何在ConstraintLayout中将TextView放在ImageVew之上

    我正在使用ConstraintLayout。我想在ImageView上放置一个TextView在ConstraintLayout中找不到此功能?xml version=1.0 encoding=utf-8? android.support....

  8. 如何在Android中将TextView添加到LinearLayout

    我试图TextViews在代码中添加到xml定义的布局中。我有一个xml工作表,其中Views定义了很多。但是我必须在代码中添加一些视图,因此LinearLayout在xml-sheet中创建一个: LinearLayout xmlns:...

  9. 如何在Android的TextView中将两行文本居中?

    我想让它看起来像这样: | two | | lines | 这是当前的布局,根本无法使用。 RelativeLayout android:layout_widt...

  10. 如何在循环中将TextView逐一添加到ListView中?

    如何在循环中将TextView逐一添加到LinerLayout中?我有一个对象的循环,我想在运行循环时将TextView添加到ListView中。我想在一段时间内添加文本!但是使用这个代码,它会在5秒后出现,而且是所有的代码!这就是我尝试过...