android TextView:如何避免换行?

问题描述 投票:0回答:1

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

如果线条对于TextView的宽度来说太长,则应显示水平滚动条。我尝试使用android:滚动条(等等)的所有内容都失败了,总有换行符。这是我的布局代码:

<?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个回答
0
投票

使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>
© www.soinside.com 2019 - 2024. All rights reserved.