![](/img/trans.png)
[英]Onclick event on textview(that has TextIsSelectable="true") is ony called on second click
[英]using textIsSelectable in textView
我将android:textIsSelectable="true"
用于TextView。
为TextView
启用复制/选择/粘贴功能是可以的
问题
当我打开此活动时,它会自动滚动到中间,例如此链接
为什么会发生此问题?
这是我的布局代码。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res/android" >
<data>
<variable
name="aboutMbti"
type="mbtitest.kiars.me.mbti.model.AboutMbti"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="2dp"
app:cardElevation="5dp" >
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:scrollbarSize="1dp"
android:scrollbarThumbVertical="@android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/img_splash_mtbi"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="3dp"
android:adjustViewBounds="true"
android:padding="5dp"
android:scaleType="centerCrop"
bind:imageUrl="@{aboutMbti.imageUrl}"/>
<TextView
android:id="@+id/txt_content_about_mtbi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/img_splash_mtbi"
android:layout_margin="5dp"
android:textIsSelectable="true"
android:padding="@dimen/title_padding"
android:text="@{aboutMbti.textContent}"
android:textColor="@color/ques_title"
android:textSize="15sp"
android:textStyle="bold"/>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</layout>
解
您可以在NestedScrollView
的子布局中添加android:focusableInTouchMode="true"
或android:descendantFocusability="blocksDescendants"
请尝试以下布局中的代码:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
...... >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true" >
...........
最后,根据https://stackoverflow.com/users/6891563/khemraj的评论,我发现
Mey解决方案...
只需将android:focusableInTouchMode="true"
到ImageView中,就像这样:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res/android" >
<data>
<variable
name="aboutMbti"
type="mbtitest.kiars.me.mbti.model.AboutMbti"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="2dp"
app:cardElevation="5dp" >
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:scrollbarSize="1dp"
android:scrollbarThumbVertical="@android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/img_splash_mtbi"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="3dp"
android:adjustViewBounds="true"
android:padding="5dp"
android:focusableInTouchMode="true"
android:scaleType="centerCrop"
bind:imageUrl="@{aboutMbti.imageUrl}"/>
<TextView
android:id="@+id/txt_content_about_mtbi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/img_splash_mtbi"
android:layout_margin="5dp"
android:textIsSelectable="true"
android:padding="@dimen/title_padding"
android:text="@{aboutMbti.textContent}"
android:textColor="@color/ques_title"
android:textSize="15sp"
android:textStyle="bold"/>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</layout>
Tnx伙计们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.