【问题标题】:Internal link to TextView in Android?Android中TextView的内部链接?
【发布时间】:2010-09-05 18:51:41
【问题描述】:

我发现自己陷入了一些我认为很容易解决的问题。我的应用程序包含很多 TextViews 和 ImageViews,一个 TextView 包含列出的内容。我希望显示内容的每个元素在内部链接到相应的 TextView。可能 TextView 不是要使用的正确元素,但我很难找到正确的元素。

内部链接应该与 html-documents 中的内部链接完全一样...这可以在 Android 中实现吗?

strings.xml:

<string name="c3">3. Contents</string>
<string name="c4">1. Abstract
\n3. Contents
\n4. List of Abbreviations
\n5. Introduction
\n6. Materials &amp; Methods
\n6.1 Literature Selection
\n6.2 Method
\n6.3 What is Android?
\n6.3.1 Dalvik Virtual Machine and Android Applications
\n6.3.2 Android Structure, Java and XML
\n6.3.3 Android Versions
\n6.4 The Development Environment
\n6.4.1 Android SDK
\n6.4.2 Eclipse IDE
\n6.4.3 Android Virtual Device
\n6.4.4 Secure Digital Card
\n6.5 “Hello World!” as Test of IDE
\n6.6 Test Application
\n6.7 Developing Strategy
\n7. Result
\n7.1 Facebook Connect
\n7.1.1 Facebook Application
\n7.1.2 Facebook Connect for Android
\n7.2 Networking
\n7.3 Data Synchronization
\n8. Discussion
\n9. Conclusion
\n10. References
\n10.1 Internet References
\n10.2 Lecture References\n\n
</string>

main.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:background="@color/smoke"
    android:scrollbars="vertical"
>
    <ScrollView android:id="@+id/ScrollView01"
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent"
        android:scrollbars="none"
    >
        <LinearLayout android:id="@+id/LinearLayout02"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="4px"
            android:paddingRight="4px"
        >

        <TextView  
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="@string/a"
            android:textColor="@color/black"
            android:gravity="center_horizontal"
            android:textSize="16dp"
            android:paddingBottom="2dp"
            android:paddingTop="20dp"
            android:scrollbars="vertical"    
        />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="@string/b"
            android:gravity="center_horizontal"
            android:textColor="@color/black"
            android:scrollbars="vertical"
        />
        <TextView  
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="@string/c1"
            android:textColor="@color/black"
            android:textSize="20dp"
            android:paddingBottom="2dp"
            android:scrollbars="vertical"
        />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="@string/c2"
            android:textColor="@color/black"
            android:scrollbars="vertical"
         />

【问题讨论】:

  • 我很困惑。我们是用ScrollView 谈论一项活动、两项活动、数十项活动还是其他?换句话说,与被“链接”到的事物相关的“链接”在哪里?
  • @CommonsWare 这是一个使用 Java 的活动不超过默认的 mainActivity.java。所有内容都在 strings.xml 中,TextViews 和 ImagesViews 的所有定义都在 main.xml 中。用户像网页一样上下滚动文档,但我想创建指向 7750 字内容部分的链接。像 html Sectiongo to section。可能吗?

标签: android hyperlink textview internal


【解决方案1】:

如果我是你,我会将你的内容转换为带有内部链接的 HTML,并使用 WebView 来显示它。我不知道您将如何以其他方式完成您正在尝试做的事情。此外,这是用于电子书的典型方法,这似乎是您正在尝试创建的。

【讨论】:

  • 在编辑我的问题时,我想到了这种方法,我相信你是对的。我已经在网页上有了内容,所以很简单。谢谢你的回答! BR
猜你喜欢
  • 1970-01-01
  • 2012-02-15
  • 2011-06-29
  • 1970-01-01
  • 2016-12-13
  • 1970-01-01
  • 1970-01-01
  • 2017-10-19
  • 2011-10-18
相关资源
最近更新 更多