user4592690 user4592690 - 5 months ago 19
Android Question

RecyclerView in viewPager above EditText

I'm building a messaging app with a viewPager to tab between multiple conversations. I have a RecyclerView in the layout inflated in the viewPager that contains my chat messages. I also have an EditText at the bottom of the layout to add a message to the RecyclerView. However when I add a new message to the adapter it is covered up by the editText. I would like the messages to remain over the input EditText like in other common messaging apps.

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">

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

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

<android.support.design.widget.TabLayout
android:id="@+id/conversation_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

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


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



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

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


and the EditText Layout

<LinearLayout
android:background="@color/input_background"
android:id="@+id/inputLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >

<EditText
android:id="@+id/input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="@dimen/input_editText_margin"
android:maxLines="2"
android:hint="Type your message..."
android:background="@android:color/transparent"
>
</EditText>

<LinearLayout
android:id="@+id/send_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/input_button_selector"
android:clickable="true"
>

<ImageButton
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_send_black_24dp"
android:background="@android:color/transparent"
android:layout_margin="@dimen/input_send_margin"
android:layout_gravity="bottom"
/>

</LinearLayout>

</LinearLayout>


before adding message

after adding message

Answer

CoordinatorLayout is a super-powered FrameLayout.

So the TextView will overlap the ViewPager. I recommend you use a RelativeLayout to contain your ViewPager and TextView. Place TextView at the bottom of parent, then put ViewPager above it.