[英]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 。
<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>
<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>
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);
}
}
}
<activity
android:name=".ScrollingActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan">
Now there are 3 problems 现在有3个问题
RecyclerView is not scrolled to bottom though I tried different options such as stackFromEnd and smoothScrollToPosition 虽然我尝试了不同的选项,例如stackFromEnd和smoothScrollToPosition,但RecyclerView并未滚动到底部
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,工具栏不会折叠,而是只是向上滚动,但工具栏的一部分显示为标题
Keeping the appbar in collapsed mode, on tap of EditText scrolls the toolbar to top and is not visible. 将appbar保持在折叠模式下,点击EditText会将工具栏滚动到顶部并且不可见。
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.