TextView/EditText 只解释 1 行

TextView/EditText Explain only 1 line

我创建了这个,有 1 个 webview 和 1 个 textview(也尝试过 edittext)和一个 scrollview,但在预览中它解释了所有行,当我启动它时只解释了 1 行。我试图 rmeove scrollview,webview...没有...我该怎么办?谢谢

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context=".ActivityMappa"
        tools:showIn="@layout/activity_mappa"

        >

        <WebView
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_marginTop="50dp"
            android:layout_marginRight="15dp"
            android:layout_marginLeft="15dp"
            android:layout_marginBottom="20dp"
            android:id="@+id/webview" />

        <EditText
            android:id="@+id/testo"
            android:layout_width="match_parent"
            android:layout_height="126dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@android:color/transparent"
            android:clickable="false"
            android:focusable="false"
            android:inputType="textMultiLine"
            android:lines="10"
            android:scrollbars="vertical"
            android:text="@string/testonavi_spawn"
            android:textSize="15sp" />

    </LinearLayout>

</ScrollView>

在 Android Studio 上预览

在我的 Phone/Emulator

上预览

Edittext 高度指定为 126dp。您将看不到其中的 30 行。所以将 edittext 的 layout_heigh 设为 "wrap_content"。这将使编辑文本动态化。由于全部内容都在滚动视图中,您仍然可以滚动并查看完整内容

strings.xml中你必须通过\'转义testonavi_spawn的所有',例如:...all\'Avamposto...

Take a look into the documentation for String resources.

您尝试过使用

android:minLines=10

其中 10 是您希望它显示的行数。

既然你已经设置了 android:width="match_parent" 也许它超出了视图将它更改为 android:layout_width="wrap_parent"

将代码改为:

<TextView
        android:id="@+id/testo"
        android:layout_width="wrap_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:minLines="10"
        android:text="@string/testonavi_spawn"
        android:textSize="15sp" />

NOTE: Always use a TextView to display the text and EditText to edit any texts.