Dic*_*cas 5 android layout-inflater android-recyclerview android-framelayout
点击一个按钮,我试图膨胀的EditText上方RecyclerView。但不是将 EditText 添加到布局的顶部,从而将 RecyclerView 向下推,而是将它简单地放置在 RecyclerView 的顶部,像这样覆盖它:

您可以看到“新文本”覆盖了 RecyclerView 的第一项。如何让它在 RecyclerView 上方膨胀,并将 RecyclerView 向下推,以容纳新添加的 EditText?
这是我将 EditText 添加到的 FrameLayout 的 XML:
<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" />
Run Code Online (Sandbox Code Playgroud)
这是我的 FloatingActionButton 的 onClick 方法,我希望在 RecyclerView 上方添加 EditText:
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);
}
Run Code Online (Sandbox Code Playgroud)
这是我添加的 EditText 的 XML:
<?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" />
Run Code Online (Sandbox Code Playgroud)
在框架布局中,所有内容都相互堆叠,如果您希望它位于回收器视图上方,请使您的布局 LinearLayout 并调用适合您的LinearLayout.addView(child, index)索引的方法0。
更新
因为你有浮动按钮,所以你的布局应该是这样的:
<FrameLayout>
<LinearLayout>
<EditText/>//witch will be added later by add view
<RecyclerView/>
</LinearLayout>
<Button/>
<FrameLayout>
Run Code Online (Sandbox Code Playgroud)
此外,如果您希望编辑文本像标题一样工作,您可以使用它:https : //stackoverflow.com/a/26573338/2127203
| 归档时间: |
|
| 查看次数: |
11137 次 |
| 最近记录: |