ExpandableTextView 中的复制功能在更改方向时会产生错误

2024-03-24

我在片段中创建了一些可扩展的文本视图,但没有启用复制功能。即使我改变方向,这也能正常工作。

但当我给android:textIsSelectable="true"在 xml TextView 中,我面临的问题是:

  • 当改变方向时,所有 TextView 的内容都会随着最后一个 TextView 的内容而改变。 我可以知道为什么会发生这种情况以及我能做些什么来解决它吗?

片段_布局.xml:

<RelativeLayout 
    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:background="#dddddd">

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <include
                android:id="@+id/sample1"
                layout="@layout/text_item" />

            <include
                android:id="@+id/sample2"
                layout="@layout/text_item" />

            <include
                android:id="@+id/sample3"
                layout="@layout/text_item" />

        </LinearLayout>
    </ScrollView>

</RelativeLayout>

text_item.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="36dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:gravity="bottom"
        android:singleLine="true"
        android:textColor="#333333"
        android:textSize="18sp"
        android:padding="5dp"
        android:background="@color/title_bg_color"

        />

    <com.ms.square.android.expandabletextview.ExpandableTextView
        android:id="@+id/expand_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        expandableTextView:maxCollapsedLines="2">

        <TextView
            android:id="@id/expandable_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:fontFamily="sans-serif-light"
            android:textSize="16sp"
            android:textColor="#494848"
            android:padding="5dp"
            android:background="@color/text_bg_color"
            android:textIsSelectable="true"
            />
        <ImageButton
            android:id="@id/expand_collapse"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:padding="16dp"
            android:layout_gravity="right|bottom"
            android:background="@color/text_bg_color"
            /> <!--android:background="@android:color/transparent"-->
    </com.ms.square.android.expandabletextview.ExpandableTextView>

</LinearLayout>

活动.java:

 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_layout, container, false);

    ((TextView) rootView.findViewById(R.id.sample1).findViewById(R.id.title)).setText(Html.fromHtml("<font color=#ffffff> A</font>"));
    ((TextView) rootView.findViewById(R.id.sample2).findViewById(R.id.title)).setText(Html.fromHtml("<font color=#ffffff> B</font>"));
    ((TextView) rootView.findViewById(R.id.sample3).findViewById(R.id.title)).setText(Html.fromHtml("<font color=#ffffff> C</font>"));

    ExpandableTextView expTv1 = (ExpandableTextView) rootView.findViewById(R.id.sample1)
            .findViewById(R.id.expand_text_view);

    ExpandableTextView expTv2 = (ExpandableTextView) rootView.findViewById(R.id.sample2)
            .findViewById(R.id.expand_text_view);

    ExpandableTextView expTv3 = (ExpandableTextView) rootView.findViewById(R.id.sample3)
            .findViewById(R.id.expand_text_view);

    expTv1.setText(Html.fromHtml(getString(R.string.A)));
    expTv2.setText(Html.fromHtml(getString(R.string.B)));
    expTv3.setText(Html.fromHtml(getString(R.string.C)));

    return rootView;
}

启用复制时的屏幕截图: 景观内容发生变化 https://i.stack.imgur.com/rFwI8.png and 纵向内容发生变化 https://i.stack.imgur.com/RbrNN.png


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ExpandableTextView 中的复制功能在更改方向时会产生错误 的相关文章

随机推荐

  • SharePoint 列表项权限

    我想以编程方式实现它 以便用户只能看到列表中的特定项目 基本上 在创建项目时运行的工作流程中 我将执行一些操作并通知一些人有关此项目的信息 我还希望它更改项目的权限 以便只有特定用户 根据项目内容在运行时查找 才能读取该项目 有权访问该列表
  • 如何轻松更改PNG图像的颜色? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我有代表扑克牌的 PNG 图像 它们是标准颜色 梅花和黑桃是空白 方块和红心是红色 我想通过将梅花转换为绿色 将方块转换为蓝色来创建
  • 使用 php 从给定 URL 下载文件,通过传递用户名和密码进行 http 身份验证

    我需要使用 php 代码下载文本文件 该文件具有 http 身份验证 我应该为此使用什么程序 我应该使用fsocketopen或卷曲或有其他方法可以做到这一点吗 我正在使用 fsocketopen 但它似乎不起作用 fp fsockopen
  • OSX:如何从 IOUSBDeviceInterface 或位置 id 获取卷名称(或 bsd 名称)

    我正在尝试编写一个应用程序 将特定的 USB 字符串描述符 USB 大容量存储设备 与其卷或 bsd 名称相关联 因此 代码会遍历所有连接的 USB 设备 获取字符串描述符并从其中之一提取信息 我想获取这些 USB 设备的卷名 我找不到合适
  • android:noHistory="true" 是如何工作的?

    假设我有一个带有菜单的基本活动 当我单击菜单项 A 时 它会转到活动 A 我再次打开菜单 然后转到 B 从 B 返回到 A 这样来回一会儿 所以堆栈将是 A B A B A B 当我按下后退按钮时 它会按预期向后浏览堆栈 然而 假设我不想要
  • v-bind 错误:v-bind' 是未声明的前缀

    我正在 asp net 中使用 Orckestra CMS 在 Composite 之前 和 Razor 模板 并尝试使用 Vue 框架 使用 option text 时一切都很好
  • Jtable 编辑单元格的外观和感觉

    有一个JTable with DefaultTableModel 有桌子的setforeground setbackground and setselectioncolor方法 另外 当您编辑单元格时 您有table setDefaultE
  • 获取图像的特定部分(图片)

    我想剪切图片的特定部分 并用它来将裁剪后的图像与硬盘中存储的另一图像进行比较 问题是我不知道如何获取源图像的 特定部分 我知道要裁剪的图像的位置 X Y 这将加载原始文件并创建一个从 0 0 开始 尺寸为 64x64 的裁剪版本 Bitma
  • MVVM 中的故事板动画

    我试图淡入然后淡出文本块以在 MVVM 中显示成功消息 但我无法让它再次淡出 我看了这个 WPF MVVM 属性更改动画 https stackoverflow com questions 1649828 wpf mvvm property
  • 错误:LaTeX 中缺少 \begin{document} [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我的 LaTeX 文档中有错误 运行我的文件时出现错误 LaTeX Error Missing begin document 和这个标签
  • 如何跟踪语速

    我正在开发一个跟踪语速的 iPhone 应用程序 并希望使用 Nuance Speechkit https developer nuance com public Help DragonMobileSDKReference iOS Spee
  • 在另一个角上绘制一个图形

    我应该如何在 R 中的另一个图的角落呈现一个小图 我知道这个问题已经结束了 但我要把这个例子留给后代 一旦掌握了基础知识 您就可以使用基本的 网格 包轻松地进行这样的自定义可视化 这是我使用的一些自定义函数的快速示例以及绘制数据的演示 自定
  • ListView 保持选中状态?

    我有一个充满项目的列表视图 在用户选择一个项目后它会亮起 然后恢复正常 有没有办法让用户在 ListView 中选择一个项目时它保持选中状态并突出显示 显然 消失的选择 是有意设计的 这是一种叫做 触摸模式 http developer a
  • Spring Boot 使用 SpringPhysicalNamingStrategy 实现多数据源

    需要配置多个数据源的 Spring boot 应用程序 多个数据源配置正在使用单独的datasource entityManager and transactionManager 此外 休眠命名配置还可以使用具有以下配置的单个数据源 spr
  • Git:如何提交未跟踪的内容?

    概要 git status 给出 未暂存提交的更改 使用 git add 来更新 将承诺什么 使用 git checkout 来丢弃 工作目录的更改 提交或丢弃未跟踪的或 修改子模块中的内容 修改的 修改内容 未跟踪内容 In case g
  • Delta Lake 回滚

    需要一种优雅的方式将 Delta Lake 回滚到以前的版本 我目前的方法如下 import io delta tables val deltaTable DeltaTable forPath spark testFolder spark
  • Pow() 计算错误?

    我需要在我的 C 程序中使用 pow 如果我调用pow 这样运行 long long test pow 7 e Where e 是一个整数值 值为 23 我总是得到821077879因此 如果我用Windows计算器计算它我得到273687
  • 奇怪的@IBAction 冲突或错误? (迅速)

    所以我得到了我的简单 iOS 应用程序的代码 当我按下 touchPressed 按钮时 该按钮应该在屏幕上获得一个新的随机位置 并且 labelScore 应该根据按钮触摸的次数进行自我更新 我的一个朋友在 Objective C 中尝试
  • 如何使用 HTTPClient 设置 HTTP 请求标头“身份验证”?

    我想在向服务器发送 POST 请求时设置 HTTP 请求标头 授权 我该如何在 Java 中做到这一点 HttpClient 有支持吗 http www w3 org Protocols HTTP HTRQ Headers html z9
  • ExpandableTextView 中的复制功能在更改方向时会产生错误

    我在片段中创建了一些可扩展的文本视图 但没有启用复制功能 即使我改变方向 这也能正常工作 但当我给android textIsSelectable true 在 xml TextView 中 我面临的问题是 当改变方向时 所有 TextVi