Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] How to set a Custom View (not an image) at the end of a multiline TextView in Android?

Posted on November 11, 2022 By

Solution 1 :

simply: you can’t.

in posted example you aren’t adding ImageView, you are adding ImageSpan with just drawable, thats very not the same…

Views can’t hold/host other Views, you have to use ViewGroup or some subclass

easiest way would be to make some LinearLayout with vertical orientation and two Views: TextView and your custom View. second one may have android:visibility="gone" and you can show it only when needed

Problem :

I am trying to add a custom view (the portion with red boundary will be replaced with my custom view having a 3 dots loader animation) at the end of a multi-line TextView in my Android app.

enter image description here

I know how to specifically add an ImageView using a SpannableString like this:-

fun addImageToEndOfTheString(text: String, drawableResourceId : Int ,context: Context) : SpannableStringBuilder {
        val drawable = ContextCompat.getDrawable(context, drawableResourceId)!!
        drawable.setBounds(0, 0, 98, 50)
        val rocketImageSpan = ImageSpan(drawable, ImageSpan.ALIGN_BASELINE)

        val ssBuilder = SpannableStringBuilder(text)

        ssBuilder.setSpan(
            rocketImageSpan,
            text.length-1,
            text.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )

        return ssBuilder
    }

But the problem is I have a custom view which I want to place at the end of my TextView. How can I achieve that?

Note : My custom view is a subclass of View.

Comments

Comment posted by Rohit Singla

but the problem will be my

Comment posted by convert your

hard, but “proper” way – your

READ  [FIXED] "interrupted by signal 5: SIGTRAP" Android emulator - macos
Powered by Inline Related Posts
Android Tags:android, android-custom-view, multiline, spannablestringbuilder, textview

Post navigation

Previous Post: [FIXED] android – LottieAnimationView doesn’t show in my_layout.xml
Next Post: [FIXED] android – Firestore conditional array query

Related Posts

[FIXED] android – How to open a pdf using android_intent_plus in flutter? Android
[FIXED] android – How to pass a lambda as an extra of an Intent? Android
[FIXED] react native – Network request failed on Android device using fetch Android
[FIXED] xamarin.android – I get this error even though I do have debuggable set: The application does not have the ‘android:debuggable’ attribute set in the AndroidManifest.xml Android
[FIXED] HttpClient.SendAsync throws ObjectDisposedException on Xamarin.Forms Android but not on UWP Android
[FIXED] android – how do i sign my app with the .jks file i have Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme