在我的android项目中,每当我在文本中插入超链接时,超链接都会起作用,但我文本的其余部分都会消失。 超链接显示在屏幕中间,周围没有可见的文字,而我清楚地在strings.xml写了很多文字。
这是它的样子截图:
这就是我在Graphic布局中的样子。 在该文本下面是链接:
这是我的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>在我的字符串中我只有很多文本,它不适合我的屏幕,这就是我添加Scrollview的原因。 有人有解决方案吗?
In my android project, whenever I insert an hyperlink in my text, the hyperlink works, but the rest of my text just disappears. The hyperlink is shown in the middle of the screen, there is no text visible around it, while I clearly have a lot of text written in my strings.xml.
This is a screenshot on how it looks like:
This is how it looks like in my Graphic layout. Underneath that text is the link:
This is my MainActivity code:
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)); } }This is my layout activity code:
<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>In my strings I just have a lot of text, it doesn't fit in my screen, that's why I have added a Scrollview. Does anyone have a solution for this?
最满意答案
用以下内容替换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>Replace your ScrollView with this:
<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>更多推荐
发布评论