对话框片段中的Scrollview无法滚动,Android吗?

时间:2019-04-04 08:56:19

标签: android scrollview android-dialogfragment

这是我的xml布局

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:background="@android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="20dp">

    <ImageView
        android:id="@+id/colse"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_marginTop="15dp"
        android:layout_marginEnd="20dp"
        android:src="@drawable/ic_close_black"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/welcomeTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:gravity="center"
        android:text="@string/welcome_to_app"
        android:textAllCaps="true"
        android:textColor="#4a4a4a"
        android:textSize="12sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/colse" />

    <TextView
        android:id="@+id/profileTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:gravity="center"
        android:text="@string/set_up_profile"
        android:textColor="@android:color/black"
        android:textSize="16sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/welcomeTitle" />

    <TextView
        android:id="@+id/profileTos"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:gravity="center"
        android:text="@string/profile_tos"
        android:textColor="@android:color/black"
        android:textSize="12sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/profileTitle" />

    <android.support.design.widget.TextInputLayout
        android:id="@+id/firstNameInput"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/profileTos">

        <EditText
            android:id="@+id/firstName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/black"
            android:hint="@string/first_name"
            android:textColor="@android:color/black"
            android:textSize="14sp"
            android:theme="@style/AppTheme.LighterEditText" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/lastNameInput"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp"
        app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/firstNameInput">

        <EditText
            android:id="@+id/lastName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/black"
            android:hint="@string/last_name"
            android:textColor="@android:color/black"
            android:textSize="14sp"
            android:theme="@style/AppTheme.LighterEditText" />
    </android.support.design.widget.TextInputLayout>


    <android.support.constraint.Guideline
        android:id="@+id/centered"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.50" />

    <TextView
        android:id="@+id/gender"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:text="@string/gender"
        android:textColor="@android:color/black"
        android:textSize="12sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/centered"
        app:layout_constraintTop_toBottomOf="@id/lastNameInput" />

    <View
        android:id="@+id/genderSeparator"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:background="#979797"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/centered"
        app:layout_constraintTop_toBottomOf="@id/gender" />

    <TextView
        android:id="@+id/birthday"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:text="@string/birthday"
        android:textColor="@android:color/black"
        android:textSize="12sp"
        app:layout_constraintLeft_toRightOf="@+id/centered"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/lastNameInput" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:background="#979797"
        app:layout_constraintLeft_toRightOf="@+id/centered"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/birthday" />


    <TextView
        android:id="@+id/birthdayOffer"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="5dp"
        android:layout_marginRight="20dp"
        android:text="@string/birthday_offer"
        android:textColor="#7a7a7a"
        android:textSize="10sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/genderSeparator" />

    <android.support.design.widget.TextInputLayout
        android:id="@+id/fitnessGoalInput"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp"
        app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/birthdayOffer">

        <EditText
            android:id="@+id/fitnessGoal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/black"
            android:hint="@string/fitness_goal"
            android:textColor="@android:color/black"
            android:textSize="14sp"
            android:theme="@style/AppTheme.LighterEditText" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/fitnessLevelInput"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp"
        app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/fitnessGoalInput">

        <EditText
            android:id="@+id/fitnessLevel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/black"
            android:hint="@string/current_fitness_level"
            android:textColor="@android:color/black"
            android:textSize="14sp"
            android:theme="@style/AppTheme.LighterEditText" />
    </android.support.design.widget.TextInputLayout>

    <TextView
        android:id="@+id/typeOfClass"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:text="@string/type_of_classes"
        android:textColor="@android:color/black"
        android:textSize="12sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/fitnessLevelInput" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/classCategory"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/typeOfClass" />

    <View
        android:id="@+id/categorySeparator"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:background="#979797"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/classCategory" />

    <Button
        android:id="@+id/save"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/rectangle_black_round_corner"
        android:text="@string/save"
        android:textColor="@android:color/white"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/categorySeparator" />

    <ProgressBar
        android:id="@+id/app_cms_page_loading_progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</ScrollView>

这是对话框片段的Java代码

public class ProfileSetupDialog extends DialogFragment {
public ProfileSetupDialog() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.profile_setup, container);
    ButterKnife.bind(this, view);
    return view;
}

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final RelativeLayout root = new RelativeLayout(getActivity());
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    final Dialog dialog = new Dialog(getActivity());
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(root);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    height = height - 120;
    dialog.getWindow().setLayout(width, height);
    dialog.getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    return dialog;
}

}

我的对话框上有多个编辑文本,因此出现的问题是键盘隐藏了用户正在为其键入内容的编辑文本,而scrollview无法滚动对话框。有解决方案吗?

我的活动已经包含

android:windowSoftInputMode="adjustResize|stateAlwaysHidden|adjustPan"

0 个答案:

没有答案