当键盘打开时,CoordinatorLayout中包含的RecyclerView未调整大小

时间:2016-01-17 09:29:12

标签: android android-layout android-recyclerview android-coordinatorlayout

活动布局xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/hospital_logo" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:orientation="vertical"
                    android:padding="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="******* ************* ********** ************"
                        android:textSize="18sp"
                        android:textColor="@android:color/black"
                        android:textStyle="bold"/>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="***************************"
                        android:textSize="18sp"
                        android:textColor="@android:color/black"
                        android:textStyle="bold"/>

                </LinearLayout>

            </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

我在CoordinatorLayoutCollapsingToolbarBar使用ViewPager

我在ViewPager中添加了两个片段,其中包含布局xml:

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />

</LinearLayout>

recycler_view的单元格包含EditText。当我选择EditText时,SoftKeyboard会打开,但EditText会隐藏在键盘后面。

我在活动中添加了以下标志:

android:windowSoftInputMode="adjustResize"

我正在使用RecyclerView的23.1.1 appcompat版本。

当我用CoordinatorLayout LinearLayout替换RecyclerView时,调整大小以正确显示最后一个元素。所以我认为这是协调员布局的问题。

我经历了以下问题https://code.google.com/p/android/issues/detail?id=176406https://code.google.com/p/android/issues/detail?id=176187,但它与此错误无关。如果我可以应用一些途径来解决这个问题,请告诉我。

等待回复。谢谢。 如果需要更多细节,请告诉我。

1 个答案:

答案 0 :(得分:2)

有一个非常类似的问题,并且可以使用Total 7266 (delta 1071), reused 0 (delta 0) remote: Compressing source files... done. List item remote: Building source: remote: remote: -----> Ruby app detected remote: -----> Compiling Ruby/Rails remote: -----> Using Ruby version: ruby-2.2. remote: -----> Installing dependencies using bundler 1.11.2 remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment remote: Installing i18n 0.7.0 remote: Installing json 1.8.3 with native extensions remote: Installing rake 11.1.2 remote: Installing minitest 5.8.4 remote: Installing thread_safe 0.3.5 remote: Installing builder 3.2.2 remote: Installing erubis 2.7.0 remote: Installing mini_portile2 2.0. remote: Installing rack 1.6.4 remote: Installing mime-types-data 3.2016.0221 remote: Installing arel 6.0.3 remote: Installing execjs 2.6.0 remote: Installing bcrypt 3.1.11 with native extensions remote: Installing sass 3.4.22 remote: Installing coffee-script-source 1.10.0 remote: Installing thor 0.19.1 remote: Installing concurrent-ruby 1.0.1 remote: Installing orm_adapter 0.5.0 remote: Installing multi_json 1.11.2 remote: Installing pg 0.18.4 with native extensions remote: Using bundler 1.11.2 remote: Installing rails_serve_static_assets 0.0.5 remote: Installing rails_stdout_logging 0.0.5 remote: Installing tilt 2.0.2 remote: Installing tzinfo 1.2.2 remote: Installing nokogiri 1.6.7.2 with native extensions remote: Installing rack-test 0.6.3 remote: Installing warden 1.2.6 remote: Installing mime-types 3.0 remote: Installing autoprefixer-rails 6.3.5 remote: Installing uglifier 3.0.0 remote: Installing coffee-script 2.4. remote: Installing sprockets 3.5.2 remote: Installing rails_12factor 0.0.3 remote: Installing mail 2.6.4 remote: Installing bootstrap-sass 3.3.6 remote: Installing loofah 2.0.3 remote: Installing rails-html-sanitizer 1.0.3 remote: Installing activesupport 4.2. remote: Installing rdoc 4.2.2 remote: Installing rails-deprecated_sanitizer 1.0.3 remote: Installing globalid 0.3.6 remote: Installing activemodel 4.2.5 remote: Installing jbuilder 2.4.1 remote: Installing activejob 4.2.5 remote: Installing rails-dom-testing 1.0.7 remote: Installing activerecord 4.2.5 remote: Installing actionview 4.2.5 remote: Installing actionpack 4.2.5 remote: Installing sdoc 0.4.1 remote: Installing actionmailer 4.2.5 remote: Installing railties 4.2.5 remote: Installing sprockets-rails 3.0.4 remote: Installing coffee-rails 4.1.1 remote: Installing responders 2.1.2 remote: Installing jquery-rails 4.1.1 remote: Installing rails 4.2.5 remote: Installing sass-rails 5.0.4 remote: Installing turbolinks 2.5.3 remote: Installing devise 3.5.6 remote: Bundle complete! 15 Gemfile dependencies, 60 gems now installed. remote: Gems in the groups development and test were not installed. remote: Bundled gems are installed into ./vendor/bundle. remote: Post-install message from rdoc: remote: Depending on your version of ruby, you may need to install ruby rdoc/ri data: remote: <= 1.8.6 : unsupported remote: = 1.8.7 : gem install rdoc-data; rdoc-data --install remote: = 1.9.1 : gem install rdoc-data; rdoc-data --install remote: >= 1.9.2 : nothing to do! Yay remote: Bundle completed (22.56s) remote: Cleaning up the bundler cache remote: sh: 2: Syntax error: Unterminated quoted string remote: sh: 2: Syntax error: Unterminated quoted string remote: ! remote: ! Could not detect rake tasks remote: ! ensure you can run `$ bundle exec rake -P` against your app remote: ! and using the production group of your Gemfile. remote: ! rake aborted! remote: ! LoadError: cannot load such file -- /tmp/build_81c00152de97c61281a1204214d29edb/website/config/application remote: ! /tmp/build_81c00152de97c61281a1204214d29edb/website/Rakefile:4:in `require remote: ! /tmp/build_81c00152de97c61281a1204214d29edb/website/Rakefile:4:in `<top (required)>' remote: ! /tmp/build_81c00152de97c61281a1204214d29edb/website/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/rake_module.rb:28:in `load'

来修复它