【问题标题】:TextView/EditText Explain only 1 lineTextView/EditText 只解释 1 行
【发布时间】:2018-08-04 15:04:24
【问题描述】:

我已经创建了这个,有 1 个 webview 和 1 个 textview(也尝试过 edittext)和一个滚动视图,但是在预览中它解释了所有行,当我启动它时只解释 1 行。我试图 rmeove 滚动视图,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上的预览

在我的手机/模拟器上预览

【问题讨论】:

  • 你想达到什么目的?什么都听不懂
  • 一个简单的webview,一个webview下,一个30行的文本
  • 你知道webview的使用吗???如果您只想显示文本,为什么需要 webview?
  • 不,我将 webview 用于可缩放图像,我将 twxtview 用于文本...
  • 但这并不重要,如果我关闭 webview,textview 只显示 1 行

标签: android android-activity text scroll textview


【解决方案1】:

strings.xml 中,您必须将testonavi_spawn 中的所有' 转义为\',例如:...all\'Avamposto...

查看documentation 获取字符串资源。

【讨论】:

  • 您不能在ScrollView 下将layout_height 设置为match_parent
  • 另外,为什么他要显示文本时要使用EditText。
  • 对于第一个评论你可以,尽管 ide 建议不要这样做,这没有什么区别,第二个不要问我。
  • 仅供参考,它在某些手机上崩溃,遇到了这个问题.. 和第二个大声笑。
  • 很高兴知道,但事实是我从不使用它,所以我会删除它
【解决方案2】:

Edittext 高度为 126dp。您将无法在其中看到 30 行。所以将edittext的layout_heigh设置为“wrap_content”。这将使edittext 动态化。由于全部内容都在滚动视图中,您仍然可以滚动并查看完整内容

【讨论】:

  • 我也试过了,在edittext和textview中都试过了,但是什么都没有,它只显示1行
  • 好像你在使用一些特殊字符。您可以删除单引号并尝试一下。如果成功了,你可以使用转义字符来使用特殊字符
  • 用“'”替换'
  • 为什么?___________
  • "'" 在 xml 中被视为单引号。双引号+单引号+双引号
【解决方案3】:

你尝试过使用

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" />

注意:始终使用TextView 显示文本,使用EditText 编辑任何文本。

【讨论】:

  • 我试过了,但它不起作用,它给出了同样的问题
  • 删除fillViewPort in ScrollView..卸载您的应用程序并尝试重新安装它。使缓存无效并重新启动。如果您像我一样运行代码,似乎没有问题.. 尝试过并为我工作..
猜你喜欢
  • 2015-05-30
  • 2013-12-22
  • 1970-01-01
  • 2013-03-10
  • 2013-12-03
  • 2017-05-04
  • 2013-12-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多