有没有一种方法可以在键盘打开时仅跳转edittext而不跳转整个布局?

时间:2020-08-24 14:40:49

标签: android android-bottomsheetdialog tiktoktemplate

我正在尝试使用底部表单对话框片段,但是每当键盘打开时,布局也会像recyclerview一样跳入片段,已经尝试过AdjustPan和AdjustNothing但没有成功。

任何人都可以帮我吗(需要类似tiktok UI注释部分的内容)

  • 已经对此[https://stackoverflow.com/questions/55788594/remaking-tiktoks-comments-ui-sticky-edittext-at-the-bottom]进行了尝试,但在我的情况下不起作用

我尝试过的一些xml代码段

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

        <TextView
            android:id="@+id/no_of_comments"
            android:layout_width="match_parent"
            android:layout_height="36dp"
            android:gravity="center_vertical|center_horizontal"
            android:text="30.8k comments"
            android:textColor="@color/graycolor" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="300dp">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/comments_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </ScrollView>
        
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_gravity="bottom"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/top_gray_line"
            android:hint="Leave a comment"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:textSize="12sp" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:alpha="0.3"
            android:background="@android:color/white"
            android:hapticFeedbackEnabled="true"
            android:src="@drawable/ic_send_pink" />

    </RelativeLayout>

</FrameLayout>

1 个答案:

答案 0 :(得分:0)

您可以尝试以下操作: activity_main:

<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:padding="20dp"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="126dp"
        android:ems="10"
        android:hint="This is EditText"
        android:gravity="center" >
    </EditText>

</RelativeLayout>

AndroidManifest:

<activity android:name=".MainActivity"
            android:windowSoftInputMode="stateVisible|adjustPan">
            <intent-filter>
                ...
            </intent-filter>
</activity>

对于类似这样的输出: enter image description here