【问题标题】:Android: On Keyboard Show, Pin ScrollView to BottomAndroid:在键盘显示中,将 ScrollView 固定到底部
【发布时间】:2019-06-23 05:34:32
【问题描述】:

目标

当显示键盘时,我希望屏幕上最底部的元素始终可见。

当前实施

我尝试过的当前实现(如下所述)在允许内容滚动方面起作用;但是,我未能让滚动视图默认位于滚动的底部。

AndroidManifest.xml

 <activity
        android:name=".OnboardingActivity"
        android:configChanges="orientation"
        android:windowSoftInputMode="stateVisible|adjustResize"
        android:label="@string/title_activity_onboarding"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme" />

片段

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        layout="@layout/toolbar_default" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none">

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


           <!-- Here are a bunch of elements, the bottommost of which I would like visible when the keyboard is shown -->

        </LinearLayout>

    </ScrollView>

</LinearLayout>

【问题讨论】:

    标签: android android-softkeyboard android-scroll


    【解决方案1】:

    在我的脑海中,这就是我将如何实现它。

    检查软键盘的可见性。从this,您可以获得可见性状态。如果键盘可见,请这样做:

    scrollView.fullScroll(View.FOCUS_DOWN);
    

    干杯!

    【讨论】:

      猜你喜欢
      • 2019-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多