gpt4 book ai didi

android - CoordinatorLayout 内的水平 RecyclerView

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:02:18 30 4
gpt4 key购买 nike

我是 Android 开发的新手,我在 android Lollipop 设备中使用 CoordinatorLayout,问题是我有一个水平滚动的 recyclerview 在滚动具有垂直滚动效果的 recyclerview 时折叠。如果我不滚动水平 recyclerview,它工作正常,如果我滚动水平 ScrollView ,一旦它不折叠。

我的代码是activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

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

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="160dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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

<android.support.v7.widget.RecyclerView
android:id="@+id/recommendedFoodItemsHolder_part1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax" />

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

<android.support.v7.widget.RecyclerView
android:id="@+id/recommendedFoodItemsHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

</LinearLayout>

我的MainActivity.java是

package in.venkatesh.www.testapp2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;


public class MainActivity extends AppCompatActivity {

private RecyclerView mSimpleRecyclerView, recommendedRecyclerView;
// private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager,recommendedLayoutManager;

private String[] mRecyclerViewValues =
new String[]{"Apple Pie", "Banana Bread", "Cupcake", "Donut", "Eclair", "Froyo",
"Gingerbread", "Honeycomb", "Ice Cream Sandwich", "Jelly Bean", "KitKat",
"Lollipop", "M preview"};
private String[] mRecommendedFoodItems = new String[]{"Chicken Biryani", "Mutton Biryani", "Veg Biryani","Veg Fried Rice"};


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Actionbar
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

// Link the views
mSimpleRecyclerView = (RecyclerView) findViewById(R.id.recommendedFoodItemsHolder);
recommendedRecyclerView = (RecyclerView) findViewById(R.id.recommendedFoodItemsHolder_part1);

// Use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mSimpleRecyclerView.setHasFixedSize(true);

// Use a linear layout manager
mLayoutManager = new LinearLayoutManager(this);
recommendedLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);

mSimpleRecyclerView.setLayoutManager(mLayoutManager);
recommendedRecyclerView.setLayoutManager(recommendedLayoutManager);


SimpleRecyclerViewAdapter mSimpleRecyclerViewAdapter = new SimpleRecyclerViewAdapter(mRecyclerViewValues);
SimpleRecyclerViewAdapter recommendedFoodRecyclerViewAdapter = new SimpleRecyclerViewAdapter(mRecommendedFoodItems);
mSimpleRecyclerView.setAdapter(mSimpleRecyclerViewAdapter); recommendedRecyclerView.setAdapter(recommendedFoodRecyclerViewAdapter);
}
}

最佳答案

尝试使用recycler.setNestedScrollingEnabled(false);这将解决您的问题

关于android - CoordinatorLayout 内的水平 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30848455/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com