我在片段中创建了一些可扩展的文本视图,但没有启用复制功能。即使我改变方向,这也能正常工作。
但当我给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(使用前将#替换为@)