adjustResize不使用ScrollView

时间:2018-05-15 12:01:59

标签: android

我有一个带有多个字段的表单的应用,当我点击底部的字段时,我想要调整应用的大小并滚动&专注于所述领域。但是,这种情况不会发生,键盘会显示并覆盖我的EditText。

有半透明状态栏。

这是我的活动的manifest.xml:

<activity
            android:name=".ui.editprofile.EditProfileActivity"
            android:theme="@style/AppTheme.ProfileEdit"
            android:windowSoftInputMode="stateHidden|adjustResize"
            android:parentActivityName=".ui.profile.ProfileActivity" />

这是活动XML:

<?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"
    android:theme="@style/AppTheme.ProfileEdit"
    tools:context=".ui.editprofile.EditProfileActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/profile_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/topbar_gradient"
        android:theme="@style/AppTheme.Dark"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/topbar_gradient"
            android:fitsSystemWindows="true"
            android:minHeight="?android:attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways" />
    </android.support.design.widget.AppBarLayout>


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/profile_appbar"
        android:fillViewport="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:gravity="center_horizontal">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/bg_light">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/profile_pic"
                android:layout_width="@dimen/profile_avatar_size"
                android:layout_height="@dimen/profile_avatar_size"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="@dimen/triple_spacing"
                android:layout_marginEnd="@dimen/single_spacing"
                android:layout_marginStart="@dimen/single_spacing"
                android:layout_marginTop="@dimen/triple_spacing"
                android:src="@drawable/larry"
                tools:src="@tools:sample/avatars"
                tools:targetApi="lollipop" />

            <FrameLayout
                android:id="@+id/change_avatar_clickarea"
                android:layout_width="@dimen/profile_avatar_size"
                android:layout_height="@dimen/profile_avatar_size"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginEnd="@dimen/single_spacing"
                android:layout_marginStart="@dimen/single_spacing"
                android:layout_marginTop="@dimen/triple_spacing"
                android:background="@drawable/circle_bg_translucid"
                android:clickable="true"
                android:focusable="true"
                android:foreground="?android:attr/selectableItemBackgroundBorderless">

                <ImageView
                    android:layout_width="32dp"
                    android:layout_height="32dp"
                    android:layout_gravity="center"
                    android:tint="@color/white"
                    app:srcCompat="@drawable/ic_picture" />
            </FrameLayout>

            <GridLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/profile_pic"
                android:background="@color/white"
                android:columnCount="2"
                android:orientation="horizontal">

                <View
                    style="@style/Divider"
                    android:layout_columnSpan="2" />

                <TextView
                    android:layout_width="96dp"
                    android:layout_height="48dp"
                    android:layout_marginLeft="@dimen/single_spacing"
                    android:gravity="center_vertical"
                    android:text="Name" />


                <android.support.v7.widget.AppCompatEditText
                    android:id="@+id/edit_first_name"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:layout_column="1"
                    android:maxLines="1"
                    android:inputType="text"
                    tools:text="@tools:sample/full_names" />

                <View
                    style="@style/Divider"
                    android:layout_column="1"
                    android:layout_columnSpan="1" />


                <android.support.v7.widget.AppCompatEditText
                    android:id="@+id/edit_last_name"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:layout_column="1"
                    android:maxLines="1"
                    android:inputType="text"
                    tools:text="@tools:sample/full_names" />

                <View
                    style="@style/Divider"
                    android:layout_columnSpan="2" />


                <TextView
                    android:layout_width="96dp"
                    android:layout_height="48dp"
                    android:layout_column="0"
                    android:layout_marginLeft="@dimen/single_spacing"
                    android:gravity="center_vertical"
                    android:text="Bio" />

                <android.support.v7.widget.AppCompatEditText
                    android:id="@+id/edit_bio"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textCapSentences|textMultiLine"
                    android:maxLength="2000"
                    android:maxLines="4"
                    android:layout_rowSpan="2"
                    android:lineHeight="48dp"
                    android:minHeight="48dp"
                    tools:text="@tools:sample/full_names" />

                <View
                    style="@style/Divider"
                    android:layout_columnSpan="2" />

                <TextView
                    android:layout_width="96dp"
                    android:layout_height="48dp"
                    android:layout_column="0"
                    android:layout_marginLeft="@dimen/single_spacing"
                    android:gravity="center_vertical"
                    android:text="Interests" />

                <FrameLayout
                    android:id="@+id/edit_tags_clickable"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:layout_gravity="center_vertical"
                    android:layout_rowSpan="1">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/edit_tags"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:orientation="horizontal"
                        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
                        tools:listitem="@layout/item_user_interests" />
                </FrameLayout>


                <View
                    style="@style/Divider"
                    android:layout_columnSpan="2" />

                <TextView
                    android:layout_width="96dp"
                    android:layout_height="48dp"
                    android:layout_column="0"
                    android:layout_marginLeft="@dimen/single_spacing"
                    android:gravity="center_vertical"
                    android:text="Location" />

                <android.support.v7.widget.AppCompatEditText
                    android:id="@+id/edit_location"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:maxLines="1"
                    android:inputType="text"
                    tools:text="@tools:sample/cities" />

                <View
                    style="@style/Divider"
                    android:layout_columnSpan="2" />

                <TextView
                    android:layout_width="96dp"
                    android:layout_height="48dp"
                    android:layout_column="0"
                    android:layout_marginLeft="@dimen/single_spacing"
                    android:gravity="center_vertical"
                    android:text="Phone" />

                <android.support.v7.widget.AppCompatEditText
                    android:id="@+id/edit_phone"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:enabled="false"
                    android:maxLines="1"
                    android:inputType="text"
                    android:text="+34 646411871"
                    tools:text="@tools:sample/us_phones" />

                <View
                    style="@style/Divider"
                    android:layout_columnSpan="2" />

            </GridLayout>

        </RelativeLayout>
    </ScrollView>

</LinearLayout>

样式:

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="cardViewStyle">@style/CardView</item>
        <item name="coordinatorLayoutStyle">@style/Widget.Support.CoordinatorLayout</item>
        <item name="chipStyle">@style/ChipStyle</item>
    </style>


    <style name="AppTheme.GradientStatus">
        <item name="android:statusBarColor">@color/transparent</item>
    </style>


    <style name="AppTheme.Dark" parent="Theme.MaterialComponents.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:windowFullscreen">false</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="cardViewStyle">@style/CardView</item>
        <item name="coordinatorLayoutStyle">@style/Widget.Support.CoordinatorLayout</item>
        <item name="chipStyle">@style/ChipStyle</item>
    </style>

    <style name="AppTheme.ProfileEdit">
        <item name="android:textAppearance">@style/Txt</item>
        <item name="android:textColor">@color/textColor</item>
        <item name="android:editTextStyle">@style/ProfileEditText</item>
        <item name="editTextStyle">@style/ProfileEditText</item>
        <item name="android:textSize">16sp</item>
    </style>

1 个答案:

答案 0 :(得分:1)

我有一个类似的问题,发现使用put代替修复了问题,我无法找出原因是什么,但我发现adjustPan更加界面友好,因为它没有使布局变形。 你只需要这样做:

adjustPan

在你的清单中。