android – 在scrollview或nestedScrollview中看不到Recylerview

我想在nestedScrollView中放置一个RecylerView,如下所示

activity_service_menu.xml

<android.support.v4.widget.nestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="HELLO" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp" />
    </LinearLayout>
</android.support.v4.widget.nestedScrollView>

ServiceMenuActivity.java

public class ServiceMenuTActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_service_menu_t);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
        rv.setLayoutManager(new linearlayoutmanager(getApplicationContext()));
        rv.setHasFixedSize(true);
        rv.setAdapter(new RvAdapter());
    }

    private static class RvAdapter extends RecyclerView.Adapter<RvAdapter.RvHolder> {

        @Override
        public RvHolder onCreateViewHolder(ViewGroup parent,int viewType) {
            View serviceMenuItemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_service_menu,parent,false);
            return new RvHolder(serviceMenuItemView);
        }

        @Override
        public void onBindViewHolder(RvHolder holder,int position) {

        }

        @Override
        public int getItemCount() {
            return 100;
        }

        public static class RvHolder extends RecyclerView.ViewHolder {

            public RvHolder(View itemView) {
                super(itemView);
            }
        }
    }

}

我已将linearLayout放在scrollView和nestedScrollView中.
但是RecyclerView不可见.如果我用FrameLayout或任何其他布局替换ScrollView,则可以看到RecyclerView.

我想使用nestedScrollView并在滚动recyclerView时滚动总布局.不幸的是,甚至看不到recyclerView.

解决方法

按照这个样本将了解你做错的地方.
主线是:android:fillViewport =“true”.
<android.support.v4.widget.nestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:theme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="24dp">


        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp">


        <com.app.view.CustomrecyclerView
            android:id="@+id/recycler_movie_suggestion"
            android:layout_width="match_parent"
            android:layout_height="170dp"
            android:fillViewport="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </android.support.v7.widget.CardView>

    </LinearLayout>

    </android.support.v4.widget.nestedScrollView>

相关文章

Android 通过adb shell命令查看内存,CPU,启动时间,电量等...
Monkey Android app稳定性测试工具之Monkey使用教程 by:授客...
Android 常见adb命令 by:授客 QQ:1033553122 1、 查看所有已...
这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...