【问题标题】:android TextView: How to avoid line breaks?android TextView:如何避免换行?
【发布时间】:2017-12-16 16:44:42
【问题描述】:

我试图弄清楚如何避免 TextView 中的换行符。

如果线条对于 TextView 的宽度来说太长,应该会出现一个水平滚动条。我用 android:scrollbars (等等)尝试的一切都失败了,总是有换行符。这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.zpit2u.maingate.MainGate_Logs">


<TextView
    android:id="@+id/tvTitle_Logs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:text="@string/app_logs" />



<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/historyRefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/tvTitle_Logs" >



    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dp"
        android:fillViewport="false" >


        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="de.zpit2u.maingate.MainGate_Logs">

            <TextView
                android:id="@+id/tvTitle_Logs_Clients"
                android:layout_marginTop="20dp"
                android:layout_marginStart="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="18sp"
                android:text="@string/logs_clients" />

            <TextView
                android:id="@+id/tvText_Logs_Clients"
                android:layout_below="@+id/tvTitle_Logs_Clients"
                android:layout_marginTop="10dp"
                android:layout_width="match_parent"
                android:layout_height="10dp"
                android:textSize="8sp"
                android:fontFamily="monospace" />

            <ProgressBar
                android:id="@+id/progressBarLogs"
                style="?android:attr/progressBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerInParent="true" />

        </RelativeLayout>
    </ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

RelativeLayout 中的第二个 TextView (tvText_Logs_Clients) 应该可以水平滚动。

【问题讨论】:

    标签: android textview line line-breaks word-wrap


    【解决方案1】:

    让textview水平滚动的方法。

     <HorizontalScrollView android:layout_width="match_parent"
            android:layout_height="match_parent">
            <TextView android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:scrollHorizontally="true"
                android:text="Horizontal scroll view will work now"/>
    
        </HorizontalScrollView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-30
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多