猿问

在 textView 中使用 textIsSelectable

我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">


                </RelativeLayout>


            </androidx.core.widget.NestedScrollView>


        </androidx.cardview.widget.CardView>


    </RelativeLayout>


</layout>


holdtom
浏览 414回答 2
2回答

千万里不及你

解决方案您可以添加android:focusableInTouchMode="true"或添加android:descendantFocusability="blocksDescendants"到子布局中NestedScrollView在您的布局中尝试以下代码:<android.support.v4.widget.NestedScrollView&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; ...... >&nbsp; &nbsp; <RelativeLayout&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:focusableInTouchMode="true" >&nbsp; &nbsp; ...........

qq_遁去的一_1

最后,根据https://stackoverflow.com/users/6891563/khemraj的评论,我发现我的解决方案...只需像这样添加android:focusableInTouchMode="true"到 ImageView :<?xml version="1.0" encoding="utf-8"?><layout xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; &nbsp; &nbsp; xmlns:app="http://schemas.android.com/apk/res-auto"&nbsp; &nbsp; &nbsp; &nbsp; xmlns:bind="http://schemas.android.com/apk/res/android" >&nbsp; &nbsp; <data>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <variable&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name="aboutMbti"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type="mbtitest.kiars.me.mbti.model.AboutMbti"/>&nbsp;&nbsp;&nbsp; &nbsp; </data>&nbsp; &nbsp; <RelativeLayout&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; app:layout_behavior="@string/appbar_scrolling_view_behavior">&nbsp; &nbsp; &nbsp; &nbsp; <androidx.cardview.widget.CardView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app:cardBackgroundColor="@android:color/white"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app:cardCornerRadius="2dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app:cardElevation="5dp" >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <androidx.core.widget.NestedScrollView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:fillViewport="true"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:fitsSystemWindows="true"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:scrollbarSize="1dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:scrollbarThumbVertical="@android:color/white">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RelativeLayout&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ImageView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/img_splash_mtbi"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="200dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_margin="3dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:adjustViewBounds="true"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:padding="5dp"android:focusableInTouchMode="true"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:scaleType="centerCrop"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bind:imageUrl="@{aboutMbti.imageUrl}"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/txt_content_about_mtbi"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_below="@+id/img_splash_mtbi"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_margin="5dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textIsSelectable="true"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:padding="@dimen/title_padding"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:text="@{aboutMbti.textContent}"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textColor="@color/ques_title"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textSize="15sp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textStyle="bold"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </RelativeLayout>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </androidx.core.widget.NestedScrollView>&nbsp; &nbsp; &nbsp; &nbsp; </androidx.cardview.widget.CardView>&nbsp; &nbsp; </RelativeLayout></layout>Tnx 伙计们
随时随地看视频慕课网APP

相关分类

Java
我要回答