能够在 Kotlin 中使 TextView 水平增长吗?

huangapple go评论85阅读模式
英文:

can a TextView grow horizontally in Kotlin?

问题

I'm making an interface for a landed tablet. It has a HorizontalScrollView and inside has a TextView. When I display it, the text goes all the way down and at the end of the layout the text ends abruptly. I wanted it to be continued in the following column.
This is my code now:

<HorizontalScrollView
            android:id="@+id/scrollView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:padding="20dp">

                <LinearLayout>...</LinearLayout>

                <TextView
                    android:id="@+id/txtBody"
                    android:layout_height="match_parent"
                    android:layout_width="500dp"
                    android:layout_margin="12dp"
                    android:textSize="16sp"
                    android:text="@{notice.text}"
                    tools:text="@tools:sample/lorem/random"/>

            </LinearLayout>
</HorizontalScrollView>

I've tried changing the original text to HTML and setting android:scrollHorizontally="true" for the text view, but it does not work either.

英文:

I'm making an interface for a landed tablet. It has a HorizontalScrollView and inside has a TextView. When I display it, the text goes all the way down and at the end of the layout the text ends abruptly. I wanted it to be continued in the following column.
This is my code now:

&lt;HorizontalScrollView
            android:id=&quot;@+id/scrollView&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot;
            app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;
            app:layout_constraintStart_toStartOf=&quot;parent&quot;
            app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;

            &lt;LinearLayout
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;match_parent&quot;
                android:orientation=&quot;horizontal&quot;
                android:padding=&quot;20dp&quot;&gt;

                &lt;LinearLayout&gt;...&lt;/LinearLayout&gt;

                &lt;TextView
                    android:id=&quot;@+id/txtBody&quot;
                    android:layout_height=&quot;match_parent&quot;
                    android:layout_width=&quot;500dp&quot;
                    android:layout_margin=&quot;12dp&quot;
                    android:textSize=&quot;16sp&quot;
                    android:text=&quot;@{notice.text}&quot;
                    tools:text=&quot;@tools:sample/lorem/random&quot;/&gt;

            &lt;/LinearLayout&gt;

I've tried changing the original text to html and setting android:scrollHorizontally="true" for the text view, but it does not work either...

答案1

得分: 0

The TextView does not automatically create a new column. It sticks to the size you gave it with layout_width or any hardcoded size and writes the text running text to this width. If you want one Text in multiple columns you need to calculate the contents yourself, here is a good tutorial: https://accella.net/knowledgebase/multi-column-text-displays-in-android/

英文:

The TextView does not automatically create a new column. It sticks to the size you gave it with layout_width or any hardcoded size and writes the text running text to this width. If you want one Text in multiple columns you need to calculate the contents yourself, here is a good tutorial: https://accella.net/knowledgebase/multi-column-text-displays-in-android/

huangapple
  • 本文由 发表于 2023年5月10日 15:22:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76215874.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定