简体   繁体   English

Coordinatorlayout + collpasingtoolbar + recyclerview + editText无法按预期工作

[英]Coordinatorlayout+collpasingtoolbar+recyclerview+editText not working as expected

First of all sorry to bring up another similar issue. 首先抱歉提出另一个类似的问题。 But none of the other questions could answer my challenges. 但其他问题都无法解决我的挑战。 I created a github project here https://github.com/winster/collapsingtoolbar . 我在这里创建了一个github项目https://github.com/winster/collapsingtoolbar

activity_scrolling.xml activity_scrolling.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/background_light"
        android:fitsSystemWindows="true"
        android:layout_above="@+id/footer">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/main.appbar"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:theme="@style/AppTheme.AppBarOverlay"
            android:fitsSystemWindows="true">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/main.collapsing"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp">


                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_collapseMode="pin"/>

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

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

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


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

    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="5"
        android:background="@color/colorPrimary"
        android:alpha="1"
        android:layout_alignParentBottom="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <EditText android:id="@+id/data"
            android:layout_width="0dp"
            android:layout_height="24dp"
            android:hint="Enter data"
            android:paddingLeft="10dp"
            android:background="@null"
            android:layout_marginRight="10dp"
            android:layout_marginLeft="16dp"
            android:lines="1"
            android:layout_weight="3" />

        <Button android:id="@+id/btn_send"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@null"
            android:text="SEND"
            android:textSize="16dp"
            android:textColor="@color/colorPrimary" />

    </LinearLayout>

</RelativeLayout>

content_scrolling.xml content_scrolling.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="0dp"
        android:scrollbars="vertical" />
</RelativeLayout>

ScrollingActivity.java ScrollingActivity.java

public class ScrollingActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private MyAdapter mAdapter;
    private ArrayList<Card> arrayList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scrolling);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        arrayList = new ArrayList<>();
        mAdapter = new MyAdapter(this, arrayList);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setStackFromEnd(true);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(mAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        for(int i=0;i<60;++i) {
            arrayList.add(new Card("TEXT "+i));
        }
        mAdapter.notifyDataSetChanged();
        if (mAdapter.getItemCount() > 1) {
            ((LinearLayoutManager)recyclerView.getLayoutManager()).setStackFromEnd(true);
            recyclerView.getLayoutManager().smoothScrollToPosition(recyclerView, null, mAdapter.getItemCount() - 1);
            //recyclerView.scrollToPosition(mAdapter.getItemCount()-1);
        }
    }        
}

AndroidManifest.xml AndroidManifest.xml中

<activity
        android:name=".ScrollingActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustPan">

Now there are 3 problems 现在有3个问题

  1. RecyclerView is not scrolled to bottom though I tried different options such as stackFromEnd and smoothScrollToPosition 虽然我尝试了不同的选项,例如stackFromEnd和smoothScrollToPosition,但RecyclerView并未滚动到底部

    1.1 1.1 在此输入图像描述

  2. Keeping the appbar in expanded mode, if you tap on the EditText, Toolbar is not collapsed, instead it just scrolls up, but a portion of toolbar is visible as header 保持appbar处于展开模式,如果你点击EditText,工具栏不会折叠,而是只是向上滚动,但工具栏的一部分显示为标题

    2.1 2.1 在此输入图像描述

  3. Keeping the appbar in collapsed mode, on tap of EditText scrolls the toolbar to top and is not visible. 将appbar保持在折叠模式下,点击EditText会将工具栏滚动到顶部并且不可见。

    3.1 3.1 在此输入图像描述

Remove line android:fitsSystemWindows="true" 删除行android:fitsSystemWindows="true"

and remove status bar color or change color from transparent color to some other color and change in Valus/styles.xml(v21). 并删除状态栏颜色或将颜色从透明颜色更改为其他颜色,并在Valus / styles.xml中更改(v21)。

Hope this may help U 希望这可能有助于你

if not try Changing app:layout_scrollFlags="scroll|exitUntilCollapsed" to app:layout_scrollFlags="scroll|exitUntilCollapsed"|snap 如果没有尝试更改app:layout_scrollFlags="scroll|exitUntilCollapsed"app:layout_scrollFlags="scroll|exitUntilCollapsed"|snap

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CoordinatorLayout与RecyclerView和底部固定的EditText - CoordinatorLayout with RecyclerView and bottom-pinned EditText 使用 Kotlin 的 RecyclerView 中的 EditText 不起作用 - EditText in RecyclerView with Kotlin not working 滚动时单击 CoordinatorLayout 中的 RecyclerView 不起作用 - Click not working on RecyclerView in CoordinatorLayout when scrolling 浓咖啡,当 NestedScrollView 或 RecyclerView 在 CoordinatorLayout 中时滚动不起作用 - Espresso, scrolling not working when NestedScrollView or RecyclerView is in CoordinatorLayout 滚动不适用于CoordinatorLayout中的RecyclerView - Scroll not working properly for RecyclerView inside CoordinatorLayout recyclerview下面的Edittext不起作用 - Edittext below recyclerview is not working AlertDialog中带有edittext的Recyclerview无法正常工作 - Recyclerview with edittext in AlertDialog not working 在Android中使用edittext和recyclerview - working with edittext and recyclerview in Android CoordinatorLayout与RecyclerView - CoordinatorLayout with RecyclerView 如何在 CoordinatorLayout 中使用 RecyclerView 但没有 NestedScrollview? (滚动行为不起作用) - How to use a RecyclerView in a CoordinatorLayout but without NestedScrollview ? (Scroll behaviors are not working)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM