相关疑难解决方法(0)

android.support.v7.widget.RecyclerView.onMeasure中的java.lang.NullPointerException

我尝试将RecyclerView与RecyclerView.Adapter一起使用,但这里出了点问题.我在下面发布我的代码:

布局:

   <android.support.v7.widget.RecyclerView
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topic_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)

topic_tile.xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/tile_height">

    <com.makeramen.RoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/avatar"
        android:padding="16dp"
        app:riv_corner_radius="72dp"
        android:layout_height="72dp"
        android:layout_width="72dp"
        />

    <LinearLayout
        android:id="@+id/text_layout"
        android:orientation="vertical"
        android:paddingTop="@dimen/text_padding_top_and_bottom"
        android:paddingBottom="@dimen/text_padding_top_and_bottom"
        android:paddingRight="16dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:id="@+id/title"
            android:textSize="@dimen/primary_font"
            android:paddingLeft="@dimen/text_padding_left"
            android:textColor="#000000"
            android:text="Title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <TextView
            android:id="@+id/author"
            android:textSize="@dimen/secondary_font"
            android:paddingLeft="@dimen/text_padding_left"
            android:text="author"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是在 onCreate()

public class TitleListActivity extends ActionBarActivity {

    private RecyclerView topic_view;
    private RecyclerView.LayoutManager mLayoutManager;
    private TitlelistAdapter adapter;

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

        .....

        topic_view = (RecyclerView)findViewById(R.id.topic_view); …
Run Code Online (Sandbox Code Playgroud)

java android android-recyclerview

21
推荐指数
3
解决办法
3万
查看次数

扩展RecyclerView:错误膨胀类com.example.MyRecyclerView

我想禁用RecyclerView的滚动.为此,我试图MyRecyclerView通过扩展来定义自定义RecyclerView.

MyRecyclerView.java

package com.example;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;

class MyRecyclerView extends RecyclerView {
    private boolean scrollable = true;

    public MyRecyclerView(Context context) {
        super(context);
    }

    public void setScrollingEnabled(boolean scrollable) {
        this.scrollable = scrollable;
    }

    public boolean isScrollable() {
        return scrollable;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // if we can scroll pass the event to the superclass
                if (scrollable) return super.onTouchEvent(ev);
                // only continue to handle the touch event …
Run Code Online (Sandbox Code Playgroud)

android extend android-custom-view android-5.0-lollipop android-recyclerview

3
推荐指数
1
解决办法
3496
查看次数