【问题标题】:Immediate text display即时文字显示
【发布时间】:2014-01-17 09:01:09
【问题描述】:

在我的 android 应用程序中,我有 textview 来证明我使用了 webview 的文本。我在xml 中设置背景image。但问题是,当我在应用程序的主菜单中按 button 以打开新活动以显示文本时。它的第一个显示背景和一段时间后显示文本。我想当我按下button 时立即显示文本。

代码-

setContentView(R.layout.benefits);
WebView view = new WebView(this);
view.setVerticalScrollBarEnabled(true);
((LinearLayout)findViewById(R.id.bText)).addView(view);
view.setBackgroundColor(0x00000000);
view.loadData(getString(R.string.benef), "text/html", "utf-8");

Xml-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="vertical" 
           android:layout_width="fill_parent"
           android:layout_height="fill_parent" 
           android:gravity="center_horizontal"
           android:background="@drawable/back">

    <View
        android:id="@+id/top_space_waster"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:background="@null"
        android:gravity="center"
        android:layout_weight="3" />

      <LinearLayout 
       android:id="@+id/bText"
       android:orientation="horizontal"
       android:layout_width="fill_parent" 
       android:layout_height="0dp"
       android:layout_weight="8"
       android:gravity="center">            
       </LinearLayout>

        <LinearLayout 
            android:orientation="horizontal"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
                android:layout_weight=".5"
            android:gravity="center_horizontal">

        <Button 
                android:text="BACK" 
                android:id="@+id/back2"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_gravity="center"
            android:textSize="32sp"
            android:textStyle="bold"
                    android:textColor="#FFFFFF"
            android:background="@null"  />

    </LinearLayout>

</LinearLayout>

【问题讨论】:

  • 有人建议我使用 Asynctask,但我不认为它有助于立即显示文本。
  • 显示文字需要多少时间?
  • 您首先加载您的 WebView 并使其不可见,然后单击按钮使其可见。
  • 确定如何以编程方式进行?
  • 最初让你的 webview 像这样WebView view = new WebView(this); view.setVisibility(View.INVISIBLE); 不可见,然后点击按钮view.setVisibility(View.VISIBLE);

标签: android xml webview background


【解决方案1】:

我不会使用 WebView 来证明文本的合理性,webviews 很慢。在你的情况下,我会使用:

textView.setText(Html.fromHtml("your string in form of HTML"));

- 只是一个普通的 TextView,带有 html 形式的文本

【讨论】:

    猜你喜欢
    • 2012-02-10
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 1970-01-01
    相关资源
    最近更新 更多