键盘隐藏了Recycler View上方的视图?

时间:2015-12-15 09:20:14

标签: android android-layout uiscrollview keyboard android-recyclerview

我想要的是以下几种布局:

<CoordinatorLayout>
  <ToolBar></ToolBar>
  <RelativeLayout></RelativeLayout>
  <RecyclerView></RecyclerView>
  <LinearLayout>
    <EditText></EditText>
  </LinearLayout>
<CoordinatorLayout>

但是,我的问题是,当我点击EditText时,键盘弹出并完美显示RecyclerView,但当我尝试向上滚动时,我似乎无法看到我的RelativeLayout,也看不到我的ToolBar。但是,当我没有键盘时,我可以看到一切都很好。以下是一些显示正在发生的事情的图片: This is my image before I click on the keyboard

This is my image after I click the keyboard

我理解这很可能是因为我不会让父母ScrollView嵌套整个布局,但由于我的RecyclerView,我似乎无法做到这一点。有没有。一种实现一种自定义RecyclerView的方法,所以我可以有一个ScrollView父布局或b。除了我的ToolBar之外,还能找到一些方法让我能够滚动查看我的RelativeLayoutRecyclerView?我已使用ScrollView加入了我的尝试,但当我点击RecyclerView时,我仍然只能看到EditText。任何帮助表示赞赏。谢谢!

代码: 的AndroidManifest.xml:

    <activity android:name=".com.tabs.activity.Comments"
        android:label="View Post"
        android:theme="@style/AppTheme.NoActionBar"
        android:configChanges="keyboardHidden"
        android:windowSoftInputMode="adjustPan|stateVisible|stateAlwaysHidden">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".com.tabs.activity.news_feed"/>
    </activity>

comments.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:flatui="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fresco="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:id="@+id/comments_coordinator_layout">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/comments_appbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/layout_comments">
            <RelativeLayout
                android:layout_marginTop="?attr/actionBarSize"
                android:id="@+id/view_post"
                android:layout_width="match_parent"
                android:paddingRight="5dp"
                android:paddingLeft="5dp"
                android:orientation="horizontal"
                android:layout_height="175dp"
                android:background="#e6e6e6">

                <com.facebook.drawee.view.SimpleDraweeView
                    android:layout_marginTop="15dp"
                    android:id="@+id/poster_picture"
                    android:layout_width="75dp"
                    android:layout_height="75dp"
                    android:layout_marginLeft="10dp"
                    fresco:placeholderImage="@mipmap/blank_prof_pic"
                    fresco:roundedCornerRadius="5dp"
                    fresco:roundAsCircle="true"
                    />

                <TextView
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="15dp"
                    android:layout_toRightOf="@id/poster_picture"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="15sp"
                    android:textStyle="bold"
                    android:id="@+id/poster_name"/>

                <TextView
                    android:layout_alignParentRight="true"
                    android:layout_marginTop="15dp"
                    android:layout_toRightOf="@id/poster_name"
                    android:layout_marginLeft="5dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="15sp"
                    android:id="@+id/post_date"/>

                <TextView
                    android:layout_marginLeft="5dp"
                    android:layout_toRightOf="@id/poster_picture"
                    android:layout_below="@id/poster_name"
                    android:textSize="20sp"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/view_status" />

            </RelativeLayout>


            <LinearLayout
                android:id="@+id/send_message"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:layout_alignParentBottom="true"
                android:orientation="horizontal" >

                <com.cengalabs.flatui.views.FlatEditText
                    android:id="@+id/write_comment"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="5"
                    android:paddingLeft="10dp"
                    android:gravity="bottom|left"
                    android:cursorVisible="false"
                    android:hint="Comment back!"
                    android:inputType="textMultiLine"
                    flatui:fl_fieldStyle="fl_box"
                    android:scrollHorizontally="false" />

                <com.cengalabs.flatui.views.FlatButton
                    android:id="@+id/send_comment"
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_marginLeft="5dp"
                    android:layout_gravity="center_vertical|center_horizontal"
                    android:gravity="center"
                    android:text="send"
                    flatui:theme="@array/sea"
                    flatui:fl_textAppearance="fl_light"/>
            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/view_post"
                android:layout_above="@id/send_message"
                android:id="@+id/view_comments">
            </android.support.v7.widget.RecyclerView>
        </RelativeLayout>
    </ScrollView>


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

2 个答案:

答案 0 :(得分:0)

根据:

  

我理解这很可能是因为我没有父母   嵌套整个布局的ScrollView,但我似乎无法做到   那是因为我的RecyclerView。有没有。一种方式   实现一种自定义的RecyclerView,这样我就可以ScrollView   父布局或b。找到一些方法让我能够滚动和看到   除ToolBar之外,我的RelativeLayoutRecyclerView?   我用ScrollView包含了我的尝试,但我仍然只能看到   点击RecyclerViewEditText。任何帮助   赞赏。谢谢!

因此,您需要扩展现有ScrollView视图的范围。只需将AppBarLayoutRelativeLayout视图放入新的垂直方向“LinearLayout”,因为ScrollView只需要一个视图。这个新创建的ViewGroup将是'CoordinatorLayout'的唯一子项。

包裹AppBarLayoutRelativeLayout' into new made LinearLayout , put it into existing ScrollView`。

希望你现在明白该怎么做。如果没有,请告诉我,我明天会在清晨编辑我的帖子,并用期望的代码更改您的实际代码。

答案 1 :(得分:0)

把你的 <RecyclerView> 放在一个 <LinearLayout> 并将您的 linearlayout 设置为 match_parent 但在您的 RecyclerView 中设置 height="0dp" 并像这样使用 weight="1"

    <CoordinatorLayout>
         <ToolBar></ToolBar>
         <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent">

                   <RecyclerView
                       android:layout_width="match_parent"
                       android:layout_height="0dp"
                       android:layout_weight="1"></RecyclerView>

        </LinearLayout>
        <EditText
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="bottom"
              app:layout_anchorGravity="bottom"></EditText>
    <CoordinatorLayout>

然后,当您的键盘打开时,您的回收站视图将不在键盘下,您可以滚动查看键盘下的项目

好锁