在FrameLayout中的RecyclerView上方放大视图 [英] Inflating view above RecyclerView in FrameLayout

查看:277
本文介绍了在FrameLayout中的RecyclerView上方放大视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击按钮时,我试图在RecyclerView上方使EditText膨胀.但是,与其将EditText添加到布局的顶部(从而按下RecyclerView),不如将其简单地放置在RecyclerView的顶部,像这样覆盖它:

On a button click, I am attempting to inflate an EditText above a RecyclerView. But instead of the EditText being added to the top of the layout, thus pushing down the RecyclerView, it is simply being placed on top of the RecyclerView, covering it like so:

您可以看到"New Text"正在覆盖RecyclerView的第一项.我如何才能使其膨胀到RecyclerView上方,并使RecyclerView向下推,以容纳新添加的EditText?

You can see that "New Text" is covering the first item of the RecyclerView. How can I get it to inflate above the RecyclerView, and have the RecyclerView pushed down, accommodating the newly added EditText?

这是我要在其中添加EditText的FrameLayout的XML:

Here is the XML of my FrameLayout that I am adding the EditText to:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_my_frame_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<com.melnykov.fab.FloatingActionButton
    android:id="@+id/button_floating_action"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_margin="16dp"
    android:src="@drawable/ic_action_new"
    fab:fab_colorNormal="@color/primary_dark"
    fab:fab_colorPressed="@color/primary" />

这是我的FloatingActionButton的onClick方法,我希望在其中将EditText添加到RecyclerView上方:

Here is the onClick method of my FloatingActionButton where I wish to add the EditText above the RecyclerView:

    public void onClick(View v) {
    ViewGroup parent = (ViewGroup) rootView.findViewById(R.id.fragment_my_frame_layout);
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.add_keyword_edittext, parent, true);
}

这是我要添加的EditText的XML:

Here is the XML of the EditText I am adding:

<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/edit_text_above_listview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:background="#00000000"
    android:textCursorDrawable="@null"
    android:imeOptions="actionDone"
    android:singleLine="true"
    android:text="New Text" />

推荐答案

在框架布局中,所有东西都相互堆叠,如果您希望它位于回收站视图上方,则使您的布局LinearLayout并调用方法LinearLayout.addView(child, index),该索引为0根据您的情况.

in frame layout everything stack on one another, if you want it to be above the recycler view make your layout LinearLayout and call method LinearLayout.addView(child, index) which index is 0 in your case.

更新

由于您具有浮动按钮,因此应将布局设置如下:

because you have floating button you should make your layout something like this:

<FrameLayout>
   <LinearLayout>
      <EditText/>//witch will be added later by add view
      <RecyclerView/>
   </LinearLayout>
   <Button/>
<FrameLayout>

如果您还希望编辑文本像标题一样工作,您可以使用以下命令: https://stackoverflow.com/a/26573338/2127203

also if you want the edit text to work as something like header you can use this: https://stackoverflow.com/a/26573338/2127203

这篇关于在FrameLayout中的RecyclerView上方放大视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆