【问题标题】:How to format a huge textview?如何格式化一个巨大的文本视图?
【发布时间】:2019-10-27 12:52:15
【问题描述】:

我想制作一个里面有历史的应用,包括段落、对话框和标题。如果不使用 Strings.xml 中的 HTML 标记,我该如何做到这一点?有没有办法在 Activity_main.xml 上仅使用 ScrollView 中的 TextView 来格式化(因为这是我知道的唯一方法)?

【问题讨论】:

  • 是的,这基本上就是我们所做的。尝试研究 textview 和布局的属性/元素(线性布局,相对布局,约束布局,...)
  • @L2_Paver 所以,如果我必须写一个大文本(比如,20 页),我就必须使用 HTML?
  • textview 有一个属性android:textsizeandroid:textStyle 你可以在xml布局中预先确定属性

标签: android-studio textview android-xml


【解决方案1】:

这是一个例子

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="25sp"
        android:textStyle="bold|italic"
        android:text="Title"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="The point is, that's 20 minutes of your life you'll never get back. And here’s the really sobering statistic: If you want to be 99% certain of getting just one response – just one! – be prepared to send out 114 messages.

That’s one of the reasons OkCupid users exchange about 4 million messages – a day. That's roughly 166,666 messages being sent every hour – one of which was yours. And that’s just one site.

Think of all the Tinder, Bumble, Match.com etc… messages flying around out there. Your message has a lot of competition – especially when you’re messaging the most attractive local women.

No wonder online dating can quickly turn into the most frustrating part-time job you’ll ever have!

Let's assume the initial hurdles standing between you and meeting your ideal partner have been cleared – you've chosen a dating site, written an engaging profile, and selected the perfect profile picture.

You’re ready to skip all that frustration and wasted time, and start using cut  paste messages that will get you real results fast."/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Anytime you can find a way to establish common ground, jump on the opportunity. Studies have shown that people are more comfortable around those who remind them of themselves, and if she’s more likely to respond if she feels a bond with you right off the bat.

Connecting over the shared experience of using dating sites is one way to do it. You could also create a message built around cooking, swimming, dancing, reading – whatever subjects you have in common with your target woman.

Some dating sites like Match.com allow you to do keyword searches, so you can filter specifically for women who enjoy a particular hobby."/>
    </LinearLayout>

</LinearLayout>

注意:将您的文本放入 string.xml 并像这样调用它android:text="@string/your_text" 而不是直接放入。

【讨论】:

    【解决方案2】:

    所以,如果我必须写一个巨大的文本(比如 20 页),我就必须使用 HTML?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-23
      • 1970-01-01
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多