【问题标题】:Text disappears when I insert a hyperlink插入超链接时文本消失
【发布时间】:2016-04-26 07:50:38
【问题描述】:

在我的 android 项目中,每当我在文本中插入超链接时,超链接都会起作用,但我的文本的其余部分就会消失。超链接显示在屏幕中间,周围看不到任何文字,而我的strings.xml 中显然有很多文字。

这是关于它的外观的屏幕截图:

这就是它在我的图形布局中的样子。该文本下方是链接:

这是我的 MainActivity 代码:

package com.example.rodekruis;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Html;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;

public class BWCActivity extends Activity {


     TextView HyperLink;
     Spanned Text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bwc);

        TextView textView =(TextView)findViewById(R.id.textView);
        textView.setClickable(true);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        String text = "<a href='https://www.rkz.nl/het_kinderbrandwondencentrum'> Kinderbrandwondencentrum </a>";
        textView.setText(Html.fromHtml(text));

    }

}

这是我的布局活动代码:

<LinearLayout 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"
    android:orientation="vertical"
    tools:context="com.example.rodekruis.Bezoek" >



    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:src="@drawable/rkz_logo" 
        android:layout_gravity="left" 
        android:layout_marginLeft="38dp"/>


    <ScrollView
         android:id="@+id/scrollview"
         android:layout_width="fill_parent"
         android:layout_height="364dp" >


    <TextView
        android:id="@+id/textView"
        android:layout_width="244dp"
        android:layout_height="276dp"
        android:layout_gravity="center"
        android:text="@string/title_activity_bwc"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/black" />


</ScrollView>
</LinearLayout>

在我的字符串中,我只有很多文本,它不适合我的屏幕,这就是我添加滚动视图的原因。有人对此有解决方案吗?

【问题讨论】:

    标签: java android layout hyperlink


    【解决方案1】:

    用这个替换你的ScrollView

    <ScrollView
             android:id="@+id/scrollview"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content" >
        <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/title_activity_bwc"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="@color/black" />
    
    </ScrollView>
    

    【讨论】:

    • 这会将链接放在我的屏幕顶部。其他文字仍然不可见
    • 你说的还有哪些文字?
    • 我将使用项目中显示的图形布局编辑我的帖子,看看有什么不同
    • 那个文本。该文本下方是链接,这就是为什么我在其中包含滚动视图的原因。当您启动项目时,您可以向下滚动到链接,如果文本可见,则不是。
    猜你喜欢
    • 2010-10-17
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 2011-09-22
    • 2019-11-15
    相关资源
    最近更新 更多