5

ボタンをクリックすると、EditTexta の上にan を膨らませようとしていRecyclerViewます。ただし、EditText がレイアウトの上部に追加されて RecyclerView が押し下げられるのではなく、RecyclerView の上に配置され、次のようにカバーされます。

ここに画像の説明を入力

「New Text」が 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" />

RecyclerView の上に EditText を追加する私の FloatingActionButton の onClick メソッドは次のとおりです。

    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 は次のとおりです。

<?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" />
4

4 に答える 4

6

フレームレイアウトでは、すべてが互いにスタックします。リサイクラービューの上に配置したい場合は、レイアウト LinearLayout を作成し、LinearLayout.addView(child, index)インデックスが0ケースにあるメソッドを呼び出します。

アップデート

フローティング ボタンがあるため、レイアウトを次のようにする必要があります。

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

また、編集テキストをヘッダーのようなものとして機能させたい場合は、これを使用できます: https://stackoverflow.com/a/26573338/2127203

于 2014-10-29T06:10:36.607 に答える
1

この TextView は、アイテムとして扱いたい RecyclerView のアイテムに関連していますか? その場合は、EditText を新しいビュー タイプとしてアダプターに (インデックス 0 に) 追加し、notifyItemInserted(0 ) を呼び出します。それに応じて、RecyclerView は、EditText を返すことができる onBind を呼び出します。このように、RecyclerView は、EditText でフェードしながらビューを適切にアニメーション化できます。アダプターを投稿できる場合は、comde の例を投稿させていただきます。

RecyclerView 内に追加したくない場合は、次の 2 つのオプションがあります。- フレーム レイアウトの代わりに線形レイアウトを使用し、TransitionManagerを使用してアニメーション化します。

LayoutManagerがフォーカスの変更などを処理できるように、アダプターに項目として追加することを検討する必要があると思います(また、リストの残りの部分とともに移動します)

于 2014-10-29T04:27:20.763 に答える
0

これは私のために働いた

<RelativeLayout>    
        <LinearLayout>
            <!-- A RecyclerView with some commonly used attributes -->
            <android.support.v7.widget.RecyclerView
                android:id="@+id/my_recycler_view"
                android:scrollbars="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:elevation="24dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"/>
        </LinearLayout>    
    <Button />    
</RelativeLayout>
于 2015-03-25T18:12:52.613 に答える
0

これは、フレーム レイアウトではすべてのビューが次々にスタックされるためです... FrameLayout は、画面内の領域をブロックするように設計されています。多くのビューまたは ViewGroup を frameLayout に追加できます。すべてのビューが互いに積み重ねられます...

<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">

    <LinearLayout
      />

    <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
        "@+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" />

    </LinearLayout>
</FrameLayout>

そして、EditText を膨張させたい場合は、フレーム レイアウトではなく、linearlayout に膨張させます。

于 2017-06-09T19:42:31.360 に答える