android - android TextView 中的可滚动背景

标签 android android-edittext textview

我有一个平铺背景的 TextView 定义为

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/tile" 
android:tileMode="repeat" />

工作正常,但问题是当我向下滚动阅读更多文本时,背景停留在同一个地方,而我希望它随文本滚动。 任何想法表示赞赏。

TextView 定义为:

<view xmlns:android="http://schemas.android.com/apk/res/android"
class="com.example.android.notepad.NoteEditor$LinedEditText"
android:id="@+id/note"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/app_bg_r"
android:textColor="#666666"
android:padding="5dp"
android:scrollbars="vertical"
android:fadingEdge="vertical" 
android:gravity="top"
android:textSize="22sp"
android:lineSpacingExtra ="7sp"
android:capitalize="sentences" />

LinedEditText 类除了设置自定义字体外什么都不做。

TextView 在Activity的onCreate with中设置

setContentView(R.layout.note_editor);

最佳答案

可能有一种方法可以仅使用 TextView 使其工作,但如果没有其他人提出解决方案,我建议将您的 TextView 包装在某种 ViewGroup(FrameLayout、RelativeLayout、LinearLayout 等)中,然后包装带有 ScrollView 的那个。它可能不是最佳解决方案,因为它增加了很多 View ,但它可能会起作用。

将背景设置为 ViewGroup 并使其在 TextView 周围包裹内容。让 ScrollView 处理滚动。

您可以在没有额外 ViewGroup 的情况下尝试查看背景是否适用于 ScrollView,但您可能会再次遇到同样的问题。

<ScrollView
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
   <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="@drawable/app_bg_r" >
      <TextView
           android:layout_width="wrap_content"           
           android:layout_height="wrap_content" />
   </RelativeLayout>
</ScrollView>

关于android - android TextView 中的可滚动背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8377076/

相关文章:

java - 将自定义对象数组传递给 android 中的另一个 Activity

android - 从 EditText 禁用软键盘但仍允许复制/粘贴?

java - 在 Android 项目中使用 EditText.toString() 方法取回奇怪的文本。为什么?

java - 如何使用java实时更新带有EditText的TextView

相当于 textCapSentences 的 android TextView

android - TextView 显示 "false"而不是资源文本

android - 私有(private)方法会增加 Android 中的 Dex 计数吗?

android - 类型 'Null' 不是类型 'Function' 的子类型

android - 如何从草图值计算 TextView 的 letterSpacing?

android - 取消选中 Android 中的所有复选框