Reputation: 376
I'm creating a list of items from a JSON file to display them on my app. But I cannot set the TextView
correctly so parts of longer texts are hidden without overflowing to multiple lines and behave as a marquee.
So far, this is my code:
val jsondata = Klaxon().parseArray<MTGSets>(jsonstr)
for(mtgset: MTGSets in jsondata.orEmpty()) {
val hlayout = LinearLayout(this)
val setTitle = TextView(this)
setTitle.text = mtgset.name
setTitle.ellipsize = MARQUEE
setTitle.maxWidth = 60.toPx()
setTitle.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)
hlayout.addView(setTitle)
cardsetlist.addView(hlayout)
}
But the text breaks in multiple lines instead:
This is the kind of result I'm looking for but programatically, as you can see:
The XML:
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:ellipsize="marquee"
android:isScrollContainer="false"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida. " />
Upvotes: 0
Views: 65