启动片段并滚动时键盘打开

我的片段中有一个滚动视图,当片段打开时,键盘会自动出现并专注于布局的第一个编辑文本,并且屏幕滚动,在键盘打开时我无法看到所有字段。那么,我该怎么做才能防止片段启动时出现键盘,以及如何在打开键盘的情况下查看滚动视图中的所有字段呢?


谢谢


这是 XML 的一部分


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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/personalDataLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:focusable="true"

android:focusableInTouchMode="true"

tools:context=".presentation.fragments.PersonalDataFragment">



<ScrollView

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:padding="10dp">



    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="vertical">


qq_遁去的一_1
浏览 62回答 1
1回答

喵喔喔

可聚焦的最高级别视图将被聚焦。如果获得焦点,EditTexts 会拉起键盘。但是如果你将以下内容添加到你的父View(RelativeLayout,LinearLayout等)中,那么键盘将不会自动打开android:focusable="true"android:focusableInTouchMode="true"例子:<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp;xmlns:app="http://schemas.android.com/apk/res-auto"&nbsp; &nbsp;android:layout_width="match_parent"&nbsp; &nbsp;android:focusable="true"&nbsp; &nbsp;android:focusableInTouchMode="true"&nbsp; &nbsp;android:layout_height="match_parent">
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java