【问题标题】:Android - ScrollView Scrolling is not working in android 7.0Android - ScrollView 滚动在 android 7.0 中不起作用
【发布时间】:2018-03-20 04:24:23
【问题描述】:

此活动具有用于“操作栏”功能的“应用栏布局”和“工具栏”。当我们在“软键盘”中输入数据时,在 android 4.4 版本中可以正常滚动,但在 android 7.0 版本中不能正常滚动。我也对 AndroidManifest.xml 做了一些更改。但是没有好结果。

下面是我的代码。

MainActivity.java

   public class MainActivity extends AppCompatActivity {


    @InjectView(R.id.sign_up_profile_country_auto)
    AutoCompleteTextView countryAutoTextView;

    @InjectView(R.id.profile_scroll_view)
    ScrollView profileScrollView;

    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        context = this;
        ButterKnife.inject(this);

        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

    }


    @OnClick(R.id.sign_up_profile_country_auto)
    public void goScrollUp(){

        profileScrollView.fullScroll(ScrollView.FOCUS_DOWN);
    }

}

AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.threeiteam.weightstripz">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar"
            android:windowSoftInputMode="adjustPan|adjustResize|stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

activity_main.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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.threeiteam.weightstripz.activity.MainActivity"
    android:background="@color/colorWhite">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorBlue"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            style="@style/MyDrawerArrowToggle"
            android:layout_marginTop="@dimen/toolbar_layout_top_margin">

                <LinearLayout
                    android:layout_width="@dimen/next_button_layout_width"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:gravity="center">

                    <TextView
                        android:id="@+id/profile_next_text_view"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:textSize="16dp"
                        android:text="@string/next_text"
                        android:textColor="@color/colorWhite"
                        android:gravity="center"/>

                </LinearLayout>

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

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

</LinearLayout>

content_main.xml

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

    <ScrollView android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/profile_scroll_view">

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


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginTop="@dimen/space_between_icon_and_text">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/active_profile_head_text"
                    android:textSize="@dimen/large_font_size"
                    android:textColor="@color/colorBlack" />

                <RadioGroup
                    android:id="@+id/active_radio_group"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_marginTop="@dimen/space_between_icon_and_text"
                    android:layout_marginLeft="10dp">

                    <RadioButton
                        android:id="@+id/profile_male_radio_button"
                        style="@style/radioButtonStyle1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/gender_male"
                        android:paddingLeft="20dp"
                        android:layout_marginBottom="@dimen/space_between_icon_and_text"/>


                    <RadioButton
                        android:id="@+id/profile_female_radio_button"
                        style="@style/radioButtonStyle1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/gender_female"
                        android:paddingLeft="20dp"/>


                </RadioGroup>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginTop="@dimen/section_distance">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/active_profile_birthday"
                    android:textColor="@color/colorBlack"
                    android:textSize="@dimen/large_font_size"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:background="@drawable/linear_bottom_border"
                    android:layout_marginTop="@dimen/space_between_welcome_layout_and_steps_layout"
                    android:id="@+id/profile_birthday_layout">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text=""
                        android:hint="@string/hint_birth_date"
                        android:textSize="@dimen/medium_font_size"
                        android:id="@+id/birthday_text_view"/>

                </LinearLayout>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/small_font_size"
                    android:text="@string/label_calorie_goal"
                    android:layout_marginTop="10dp"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/large_font_size"
                    android:textColor="@color/colorBlack"
                    android:layout_marginTop="@dimen/section_distance"
                    android:layout_marginBottom="@dimen/space_between_welcome_layout_and_steps_layout"
                    android:text="@string/label_location"
                    android:id="@+id/location_text_view"/>

                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">


                    <AutoCompleteTextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/sign_up_profile_country_auto"
                        android:textSize="@dimen/medium_font_size"
                        android:hint="@string/hint_country"/>

                </android.support.design.widget.TextInputLayout>


            </LinearLayout>

        </LinearLayout>

    </ScrollView>

</LinearLayout>

【问题讨论】:

  • 没有“正确”滚动是什么意思?
  • 请从 AndroidManifes 中删除 android:windowSoftInputMode="adjustPan|adjustResize|stateHidden"。这对我有用..
  • 不滚动意味着当我输入编辑文本的值时,软键盘出现并且其他内容可以在 android 4.4 中滚动,但在 android 7.0 中不能滚动
  • @ Umesh AHIR - 这不是我的问题的解决方案。
  • 当我为底部的“AutoCompleteEditText”输入数据时,由于滚动问题,我看不到正在输入的内容

标签: android scrollview android-toolbar android-appbarlayout android-version


【解决方案1】:

我认为你不需要为此做任何事情。

请更改一些代码并运行它。

删除

 @OnClick(R.id.sign_up_profile_country_auto)
public void goScrollUp(){

    profileScrollView.fullScroll(ScrollView.FOCUS_DOWN);
}

也删除 android:windowSoftInputMode="adjustPan|adjustResize|stateHidden" 来自 AndroidManifes。

当你点击 AutoCompleteTextView 屏幕自动向上滚动..

【讨论】:

  • 我做到了。但什么都没有。当我为底部编辑文本输入数据时,我看不到我在输入什么
  • 我做到了。但什么都没有。当我为底部的“AutoCompleteEditText”输入数据时,由于滚动问题,我看不到我正在输入的内容
  • 请告诉我@style/AppTheme.NoActionBar 里面是什么
  • 必须是
  • 是的,我已经有了那种风格
【解决方案2】:

将其更改为nestedScrollView。有时,当我的ScrollView 没有滚动时,我使用了NestedScrollView,效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多