turing-tech / MaterialScrollBar

An Android library that brings the Material Design 5.1 sidebar to pre-5.1 devices.
Apache License 2.0
778 stars 126 forks source link

Crash when set bar thickness #100

Closed king89 closed 7 years ago

king89 commented 7 years ago

after set this app:msb_barThickness="3dp", the app crash.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.king.myapplication/com.example.king.myapplication.ScrollBarActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class com.turingtechnologies.materialscrollbar.DragScrollBar

crash on NPE here

public T setBarThickness(int thickness){
        LayoutParams layoutParams = (LayoutParams) handleThumb.getLayoutParams();
        layoutParams.width = thickness;
        handleThumb.setLayoutParams(layoutParams);

        layoutParams = (LayoutParams) handleTrack.getLayoutParams();
        layoutParams.width = thickness;
        handleTrack.setLayoutParams(layoutParams);

        if(indicator != null){
            indicator.setSizeCustom(thickness);
        }

        layoutParams = (LayoutParams) getLayoutParams();   // <- crash, reutn null 
        layoutParams.width = thickness;
        setLayoutParams(layoutParams);

        return (T)this;
    }

Layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.turingtechnologies.materialscrollbar.DragScrollBar
        android:id="@+id/touchScrollBar"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        app:msb_lightOnTouch="true"
        app:msb_recyclerView="@id/recyclerView" />
</RelativeLayout>
jooleeanh commented 7 years ago

I experience the same crash.

androideveloper commented 6 years ago

I have the same crash, but on TouchScrollBar. I have opened a PR, please review