#StackBounty: #android #android-layout #user-interface #android-recyclerview How do I create a wheel picker for a list of custom objects?

Bounty: 50

I want to let the user choice an element from ArrayList<MyObjectType> via a wheel picker that looks similar to the wheel picker that gets used to pick the day/month/year in the data picker. While the date picker obviously has three variables, I only care about having one.

enter image description here

What’s the most straightforward way to implement such a picker?


Get this bounty!!!

#StackBounty: #android #scroll #android-recyclerview #interpolation Why doesn't smooth scroll of RecyclerView work well with some I…

Bounty: 200

Background

In an effort to make a nice&short overview of the items on a horizontal RecyclerView, we want to have a bounce-like animation , that starts from some position, and goes to the beginning of the RecyclerView (say, from item 3 to item 0) .

The problem

For some reason, all Interpolator classes I try (illustration available here) don’t seem to allow items to go outside of the RecyclerView or bounce on it.

More specifically, I’ve tried OvershootInterpolator , BounceInterpolator and some other similar ones. I even tried AnticipateOvershootInterpolator. In most cases, it does a simple scrolling, without the special effect. on AnticipateOvershootInterpolator , it doesn’t even scroll…

What I’ve tried

Here’s the code of the POC I’ve made, to show the issue:

MainActivity.kt

class MainActivity : AppCompatActivity() {
    val handler = Handler()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val itemSize = resources.getDimensionPixelSize(R.dimen.list_item_size)
        val itemsCount = 6
        recyclerView.adapter = object : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
            override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
                val imageView = ImageView(this@MainActivity)
                imageView.setImageResource(android.R.drawable.sym_def_app_icon)
                imageView.layoutParams = RecyclerView.LayoutParams(itemSize, itemSize)
                return object : RecyclerView.ViewHolder(imageView) {}
            }

            override fun getItemCount(): Int = itemsCount

            override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            }
        }
        val itemToGoTo = Math.min(3, itemsCount - 1)
        val scrollValue = itemSize * itemToGoTo
        recyclerView.post {
            recyclerView.scrollBy(scrollValue, 0)
            handler.postDelayed({
                recyclerView.smoothScrollBy(-scrollValue, 0, BounceInterpolator())
            }, 500L)
        }
    }
}

activity_main.xml

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView" 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="@dimen/list_item_size" android:orientation="horizontal"
    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>

gradle file

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
    implementation 'androidx.core:core-ktx:1.0.0-rc02'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'androidx.recyclerview:recyclerview:1.0.0-rc02'
}

And here’s an animation of how it looks for BounceInterpolator , which as you can see doesn’t bounce at all :

enter image description here

Sample POC project available here

The question

Why doesn’t it work as expected, and how can I fix it?

Could RecyclerView work well with Interpolator for scrolling ?


EDIT: seems it’s a bug, as I can’t use any “interesting” interpolator for RecyclerView scrolling, so I’ve reported about it here .


Get this bounty!!!

#StackBounty: #android #android-recyclerview #android-viewpager How to animate RecyclerView like vertical Viewpager transforms

Bounty: 100

I have used Vertical Viewpager in my project.

But there are some issues,

  1. when the page has lots of onclick() events, the scrolling is too hard

  2. fling event doesn’t change the page

  3. I tried to use gesture detector, but it changed pages too fast without transitions (without invoking transformPage())

  4. when I scroll the page, Sometimes onclick() events also get triggered

So I decided to use Recyclerview as Viewpager with the help of PagerSnapHelper.

It works fine. But the problem is ,

how to do the transition or animation when the item is changed (like I
did in ViewPager)

For example, Zoomout transition or stack transition in Viewpager.

I tried stackLayoutManager but it takes more time to scroll and tried this related link .It doesn’t work.

I researched for both issues How to reduce scroll speed for viewpager and how to do animations in recyclerview. I didn’t get solution for it.

Can anyone help me!!! is it possible or I need to use any other widgets.

Edit

I tried #ADM’s suggestion, it works fine but doesn’t support PagerSnapHelper.

I have changed stacklayout manager in the above link but it doesn’t support scrollToPosition() and PagerSnapHelper.

Code:

public class StackLayoutManager  extends LinearLayoutManager {

    private static final String TAG = "StackLayoutManager";

    //the space unit for the stacked item
    private int mSpace = 0;
    /**
     * the offset unit,deciding current position(the sum of  {@link #mItemWidth} and {@link #mSpace})
     */
    private int mUnit;
    //item width
    private int mItemWidth;
    private int mItemHeight;
    //the counting variable ,record the total offset including parallex
    private int mTotalOffset;
    //record the total offset without parallex
    private int mRealOffset;
    private ObjectAnimator animator;
    private int animateValue;
    private RecyclerView.Recycler recycler;
    private int lastAnimateValue;
    private int initialOffset;
    private boolean initial;
    private int mMinVelocityX;
    private VelocityTracker mVelocityTracker = VelocityTracker.obtain();
    private int pointerId;
    private Method sSetScrollState;
    RecyclerView recyclerView;


    public StackLayoutManager(Context context) {
        super(context, VERTICAL, false);
        setAutoMeasureEnabled(true);

    }

    @Override
    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
        this.recycler = recycler;
        detachAndScrapAttachedViews(recycler);
        //got the mUnit basing on the first child,of course we assume that  all the item has the same size
        View anchorView = recycler.getViewForPosition(0);
        measureChildWithMargins(anchorView, View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        mItemWidth = anchorView.getMeasuredWidth();
        mItemHeight = getDecoratedMeasuredHeight(anchorView);

        mUnit = mItemHeight;
        //because this method will be called twice
        initialOffset = mUnit;
        mMinVelocityX = ViewConfiguration.get(anchorView.getContext()).getScaledMinimumFlingVelocity();
        fill(recycler, 0);

    }


    @Override
    public void onLayoutCompleted(RecyclerView.State state) {
        super.onLayoutCompleted(state);
        if (!initial) {
            fill(recycler, initialOffset, false);
            initial = true;
        }
    }

    @Override
    public void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter) {
        initial = false;
        mTotalOffset = mRealOffset = 0;
    }


    private int fill(RecyclerView.Recycler recycler, int dy, boolean apply) {
        return fillFromTop(recycler, dy);
    }

    public int fill(RecyclerView.Recycler recycler, int dy) {
        return fill(recycler, dy, true);
    }

    private int fillFromTop(RecyclerView.Recycler recycler, int dy) {
        if (mTotalOffset + dy < 0 || (mTotalOffset + dy + 0f) / mUnit > getItemCount() - 1)
            return 0;
        detachAndScrapAttachedViews(recycler);
        mTotalOffset += dy;
        int count = getChildCount();
        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            if (recycleVertically(child, dy))
                removeAndRecycleView(child, recycler);
        }
        int curPos = mTotalOffset / mUnit;
        int leavingSpace = getHeight() - (left(curPos) + mUnit);
        int itemCountAfterBaseItem = leavingSpace / mUnit + 2;
        int e = curPos + itemCountAfterBaseItem;

        int start = curPos - 1 >= 0 ? curPos - 1 : 0;
        int end = e >= getItemCount() ? getItemCount() - 1 : e;

        int left = getWidth() / 2 - mItemWidth / 2;
        //layout views
        for (int i = start; i <= end; i++) {
            View view = recycler.getViewForPosition(i);

            float alpha = alpha(i);

            addView(view);
            measureChildWithMargins(view, 0, 0);
            int top =  (left(i) /* - ( 1 - scale ) * view.getMeasuredHeight() */ );
            int right = view.getMeasuredWidth() + left;
            int bottom = view.getMeasuredHeight() + top;
            layoutDecoratedWithMargins(view, left, top, right, bottom);
            view.setAlpha(alpha);
            view.setScaleY(1);
            view.setScaleX(1);
        }

        return dy;
    }


    private View.OnTouchListener mTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            mVelocityTracker.addMovement(event);
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (animator != null && animator.isRunning())
                    animator.cancel();
                pointerId = event.getPointerId(0);

            }
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (v.isPressed())
                    v.performClick();
                mVelocityTracker.computeCurrentVelocity(1000, 14000);
                float xVelocity = mVelocityTracker.getYVelocity(pointerId);
                int o = mTotalOffset % mUnit;
                int scrollX;
                if (Math.abs(xVelocity) < mMinVelocityX && o != 0) {
                    if (o >= mUnit / 2)
                        scrollX = mUnit - o;
                    else
                        scrollX = -o;
                    Log.d("scrollx","from scroll");

                    Log.d("scrollx", "" + scrollX);
                    brewAndStartAnimator(300, (int) (scrollX));
                }
            }
            return false;
        }

    };

    private RecyclerView.OnFlingListener mOnFlingListener = new RecyclerView.OnFlingListener() {
        @Override
        public boolean onFling(int velocityX, int velocityY) {
            int o = mTotalOffset % mUnit;
            int s = mUnit - o;
            int scrollX;
            int vel = absMax(velocityX, velocityY);
            if (vel  > 0) {
                scrollX = s;
            } else
                scrollX = -o;
            Log.d("scrollx","from fling");
            Log.d("scrollx",""+scrollX);
            brewAndStartAnimator(100, scrollX);
          //  setScrollStateIdle();
            return true;
        }
    };

    private int absMax(int a, int b) {
        if (Math.abs(a) > Math.abs(b))
            return a;
        else return b;
    }

    @Override
    public void onAttachedToWindow(RecyclerView view) {
        super.onAttachedToWindow(view);
        this.recyclerView=view;
        view.setOnTouchListener(mTouchListener);
        view.setOnFlingListener(mOnFlingListener);
    }


    private void brewAndStartAnimator(int dur, int finalX) {
        animator = ObjectAnimator.ofInt(StackLayoutManager.this, "animateValue", 0, finalX);
        animator.setDuration(dur);
        animator.start();
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                lastAnimateValue = 0;
                recyclerView.scrollToPosition(findFirstCompletelyVisibleItemPosition());

            }

            @Override
            public void onAnimationCancel(Animator animation) {
                lastAnimateValue = 0;
                recyclerView.smoothScrollToPosition(findFirstCompletelyVisibleItemPosition());
            }
        });

    }

    private float alpha(int position) {
        float alpha;
        int curPos = mTotalOffset / mUnit;
        float n = (mTotalOffset + .0f) / mUnit;
        if (position > curPos)
            alpha = 1.0f;
        else {
            alpha = 1 - (n - position) / 1;
        }
        return alpha <= 0.001f ? 0 : alpha;
    }

    @Override
    public void scrollToPosition(int pos)
    {
          scrollToPositionWithOffset(pos, 0);
    }

    private int left(int position) {


        int curPos = mTotalOffset / mUnit;
        int tail = mTotalOffset % mUnit;
        float n = (mTotalOffset + .0f) / mUnit;
        float x = n - curPos;

        return ltr(position, curPos, tail, x);

    }

    private int ltr(int position, int curPos, int tail, float x) {
        int left;
        if (position <= curPos) {
            if (position == curPos) {
                left = (int) (mSpace * (1 - x));
            } else {
                left = (int) (mSpace * (1 - x - (curPos - position)));

            }
        } else {
            if (position == curPos + 1)
                left = mSpace + mUnit - tail;
            else {

                int baseStart = (int) (mUnit +  mUnit);
                left = (int) (baseStart + (position - curPos - 2) * mUnit - (position - curPos - 2) * (mUnit));
                if (BuildConfig.DEBUG)
                    Log.i(TAG, "ltr: curPos " + curPos + "  pos:" + position + "  left:" + left + "   baseStart" + baseStart + " curPos+1:" + left(curPos + 1));
            }
            left = left <= 0 ? 0 : left;
        }
        return left;
    }


    @SuppressWarnings("unused")
    public void setAnimateValue(int animateValue) {
        this.animateValue = animateValue;
        int dy = this.animateValue - lastAnimateValue;
        fill(recycler, dy, false);
        lastAnimateValue = animateValue;
    }

    @SuppressWarnings("unused")
    public int getAnimateValue() {
        return animateValue;
    }


    private boolean recycleVertically(View view, int dy) {
        return view != null && (view.getTop() - dy < 0 || view.getBottom() - dy > getHeight());
    }


    @Override
    public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
        return fill(recycler, dy);
    }

    @Override
    public boolean canScrollHorizontally() {
        return false;
    }

    @Override
    public boolean canScrollVertically() {
        return true;
    }

    @Override
    public RecyclerView.LayoutParams generateDefaultLayoutParams() {
        return new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.MATCH_PARENT);
    }

    @SuppressWarnings("unused")
    public interface CallBack {

        float scale(int totalOffset, int position);

        float alpha(int totalOffset, int position);

        float left(int totalOffset, int position);
    }
}

And If it is not possible with recyclerview, Please help me what to do with that VerticalViewPager. I have tried setting the field values, But it doesn’t work.

    try {
        Class cls = this.getClass().getSuperclass();
        Field distanceField = cls.getDeclaredField("mFlingDistance");
        distanceField.setAccessible(true);
        distanceField.setInt(this, distanceField.getInt(this)/2);
    }catch (Exception ignored) {
        Log.d("error", ignored.toString());
    }


    try {
        Class cls = this.getClass().getSuperclass();
        Field minVelocityField = cls.getDeclaredField("mMinimumVelocity");
        minVelocityField.setAccessible(true);
        minVelocityField.setInt(this, minVelocityField.getInt(this) /2);
    } catch (Exception ignored) {
        Log.d("error", ignored.toString());
    }


    try {
        Class cls = this.getClass().getSuperclass();
        Field maxVelocityField = cls.getDeclaredField("mMaximumVelocity");
        maxVelocityField.setAccessible(true);
        maxVelocityField.setInt(this, maxVelocityField.getInt(this)/2);
    }catch (Exception ignored) {
        Log.d("error", ignored.toString());
    }


Get this bounty!!!

#StackBounty: #java #android #android-fragments #android-recyclerview android.content.res.Resources$NotFoundException: Unable to find r…

Bounty: 50

In my RecyclerView I need replace part of my item to my fragment.
I have followed this answer by Victor Cruz and I am able to achieve what I wanted.

Everything is working fine but I am facing one serious problem i.e I am getting Resources$NotFoundException Unable to find resource ID only in the last item of my RecyclerView, note that this problem is occurring only in the last item rest others are working fine.

Steps which I have tried:

  1. I tried to look for the resource ID in R.java file but all in vain.

  2. I have tried reducing and increasing the number of items in RecyclerView but the problem is still the same.

  3. Searched other relevant answers like assigning the same id to parent layout as passing in replace fragment.
  4. Tried catching the Exception but failed because I think it is not able to find the layout file in on create only in the case of last item.
  5. Checked if it is happening due to any type casting errors.

Please give suggestions where am I doing wrong. I will be happy to provide any other relevant details.

After 5 days of posting the Question (and struggling with this for a week), I am not able to figure problem out.
I have made a small sample app performing this particular task, You can download the code from here.

Please help me out of this.

Edit: Posting code:

private void flipcard(final RecyclerView.ViewHolder holder)
{
    final MyHolder myHolderflipcard= (MyHolder) holder;
            // Delete old fragment
            int containerId = myHolderflipcard.container.getId();// Get container id
            Fragment oldFragment = ((FragmentActivity) context).getFragmentManager().findFragmentById(containerId);
            if(oldFragment != null)
            {
                ((FragmentActivity) context).getFragmentManager().beginTransaction().remove(oldFragment).commit();
            }
            int newContainerId = getUniqueId();
            // Set the new Id to our know fragment container
            myHolderflipcard.container.setId(newContainerId);
            // Just for Testing we are going to create a new fragment according
            // if the view position is pair one fragment type is created, if not
            // a different one is used.
            {
                Fragment f;
                f = new CardBackFragment();
                // Then just replace the recycler view fragment as usually
                ((FragmentActivity) context).getFragmentManager().beginTransaction()
                        .setCustomAnimations(
                                R.animator.card_flip_right_in,
                                R.animator.card_flip_right_out,
                                R.animator.card_flip_left_in,
                                R.animator.card_flip_left_out)
                        .addToBackStack(null)
                        .replace(newContainerId, f).commit();

                myHolderflipcard.cardView.setVisibility(View.GONE);
            }
}
// Method that could us an unique id
private int getUniqueId(){
    return (int)
            SystemClock.currentThreadTimeMillis();
}

Here is my logcat if it can be of any use.

E/UncaughtException: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x1678
                                                                              at android.content.res.Resources.getResourceName(Resources.java:2209)
                                                                              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:886)
                                                                              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                                              at android.app.BackStackRecord.run(BackStackRecord.java:834)
                                                                              at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
                                                                              at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
                                                                              at android.os.Handler.handleCallback(Handler.java:739)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                              at android.os.Looper.loop(Looper.java:135)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5292)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at java.lang.reflect.Method.invoke(Method.java:372)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: **app package name //intentionally written**, PID: 3136
                                                                       android.content.res.Resources$NotFoundException: Unable to find resource ID #0x1678
                                                                           at android.content.res.Resources.getResourceName(Resources.java:2209)
                                                                           at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:886)
                                                                           at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                                           at android.app.BackStackRecord.run(BackStackRecord.java:834)
                                                                           at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
                                                                           at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
                                                                           at android.os.Handler.handleCallback(Handler.java:739)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:135)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5292)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at java.lang.reflect.Method.invoke(Method.java:372)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)


Get this bounty!!!

#StackBounty: #android #android-recyclerview RecyclerView fast srcoll thumb height too small for large data set

Bounty: 50

I am using the default recyclerview fast scroll and I followed this guide to support it.

Now, the problem is that the thumb resizes it’s height as per the size of the data set. For large items like 100 and above, the thumb becomes very small and almost becomes difficult to respond to dragging.

Please is there any way I can set minimum height for the fast scroll thumb.


Get this bounty!!!

#StackBounty: #android #android-recyclerview #android-coordinatorlayout How to move a textview into the toolbar through coordinator lay…

Bounty: 50

I’m working on building a coordinator layout that is made up of a toolbar, a relative layout that is to hide on scroll, a layout that is static always above the scrollable list, and a RecyclerView.

I currently have it laid out as I want it to, as seen here:

  • Green is the toolbar
  • Orange is the relative layout to hide on scroll
  • Red is my static layout that is to stay above the recycler view and
    move up but not hide.
  • White is my RecyclerView

This next image is what it looks like once I scroll the whole way up the recycler view.

So my orange view hides as I want it to, which is perfect. The only step i’m missing is moving the “Title 1” textview into becoming the title of the toolbar. I’ve seen examples where they have done something kind of similar with an image, but haven’t been able to duplicate it yet with a custom behavior. I’m assuming thats what this will take?

Does anyone have any advice on if my layout needs to change to make this possible, and any advice for a custom behavior if that is what this will take?

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
            <!-- HEADER -->
            <RelativeLayout
                android:id="@+id/rel1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                android:background="@color/lightGreen"
                android:layout_marginTop="?attr/actionBarSize"
                android:paddingTop="10dp"
                android:paddingBottom="10dp">
                <TextView
                    android:id="@+id/title1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:text="Resist the urge"
                    android:textSize="35sp"
                    android:includeFontPadding="true"
                    android:layout_centerInParent="true"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/resistUrgeTitleTextView"
                    android:layout_centerHorizontal="true"
                    android:text="Use a method below to help."
                    android:includeFontPadding="true"/>
            </RelativeLayout>

            <FrameLayout
                android:id="@+id/main.framelayout.title"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_gravity="bottom|center_horizontal"
                android:background="@color/lightOrange"
                android:orientation="vertical"
                app:layout_collapseMode="parallax"
                >

                <LinearLayout
                    android:id="@+id/main.linearlayout.title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:orientation="vertical"
                    >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="bottom|center"
                        android:text="Title 1"
                        android:textColor="@android:color/white"
                        android:textSize="30sp"
                        app:layout_behavior="com.uhg.ent.mobile.quit4life.UrgeIntervention.TitleTextViewBehavior"
                        />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:layout_marginTop="4dp"
                        android:text="Subtitle"
                        android:textColor="@android:color/white"
                        />

                </LinearLayout>
            </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:backgroundTint="@color/lightGreen"
                app:layout_collapseMode="pin"
                app:title=""/>
            <!--<TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|center_horizontal"
                android:text="Resist the urge"
                android:textColor="@android:color/black"
                android:textSize="30sp"
                app:layout_behavior="com.uhg.ent.mobile.quit4life.UrgeIntervention.TitleTextViewBehavior"
                />-->


        </android.support.design.widget.CollapsingToolbarLayout>
        <android.support.constraint.ConstraintLayout
            android:id="@+id/cardConstraintLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:background="@android:color/holo_red_dark"
            android:layout_marginTop="0dp">

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="0dp"
                android:layout_height="175dp"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0"
                android:paddingBottom="50dp"/>
            <android.support.design.widget.TabLayout
                android:layout_width="wrap_content"
                android:layout_height="20dp"
                android:id="@+id/viewPagerIndicator"
                app:tabBackground="@drawable/pager_indicator_selector_gray"
                app:tabGravity="center"
                app:tabIndicatorHeight="0dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@id/interventionCategoryViewPager"
                android:layout_marginBottom="10dp"/>
        </android.support.constraint.ConstraintLayout>
        <!-- </android.support.design.widget.CollapsingToolbarLayout>-->
        <!--<android.support.v7.widget.Toolbar
            android:id="@+id/main.toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            app:layout_anchor="@id/main.framelayout.title"
            app:theme="@style/ThemeOverlay.AppCompat.Dark"
            app:title=""
            app:layout_collapseMode="pin">
        </android.support.v7.widget.Toolbar>-->
    </android.support.design.widget.AppBarLayout>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    </android.support.v7.widget.RecyclerView>
  </android.support.design.widget.CoordinatorLayout>

EDIT:

I’ve got a little bit of progress made. I think I have the layout how I want, and i’ve got a behavior started. I am able to move the TextView, but it is getting lost behind the toolbar. I want it to go on top of the toolbar. My goal is to move the title from the yellow block into the green block.

Do I need to adjust my layout so make it possible for the textview to appear on top of the title bar?

enter image description here

New code 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:orientation="vertical">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="?attr/colorPrimary"
        android:backgroundTint="@color/lightOrange"
        app:title=""
        android:layout_marginTop="20dp"/>
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:gravity="bottom|center"
            android:text="Test 1"
            android:textColor="@android:color/white"
            android:textSize="30sp"
            app:layout_behavior="com.uhg.ent.mobile.quit4life.UrgeIntervention.TitleTextViewBehavior"
            android:elevation="100dp"/>
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            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="wrap_content"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
                <LinearLayout
                    android:id="@+id/main.framelayout.title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom|center_horizontal"
                    android:background="@color/lightGreen"
                    android:orientation="vertical"
                    app:layout_collapseMode="parallax"
                    android:paddingTop="50dp">
                    <!--<TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:gravity="bottom|center"
                        android:text="Resist The Urge"
                        android:textColor="@android:color/white"
                        android:textSize="30sp"
                        app:layout_behavior="com.uhg.ent.mobile.quit4life.UrgeIntervention.TitleTextViewBehavior"
                        android:paddingTop="20dp"/>-->
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:layout_marginTop="4dp"
                        android:text="Test 2."
                        android:textColor="@android:color/white"
                        android:paddingBottom="20dp"
                        />
                </LinearLayout>
            </android.support.design.widget.CollapsingToolbarLayout>
            <android.support.constraint.ConstraintLayout
                android:id="@+id/cardConstraintLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"

                android:layout_marginTop="0dp">

                <android.support.v4.view.ViewPager
                    android:id="@+id/viewPager"
                    android:layout_width="0dp"
                    android:layout_height="175dp"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0"
                    android:paddingBottom="50dp"/>
                <android.support.design.widget.TabLayout
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:id="@+id/viewPagerIndicator"
                    app:tabBackground="@drawable/pager_indicator_selector_gray"
                    app:tabGravity="center"
                    app:tabIndicatorHeight="0dp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/interventionCategoryViewPager"
                    android:layout_marginBottom="10dp"/>
            </android.support.constraint.ConstraintLayout>
        </android.support.design.widget.AppBarLayout>

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


Get this bounty!!!

#StackBounty: #android #recyclerview #android-textview #android-recyclerview "android:textIsSelectable="true" not workin…

Bounty: 50

I know that setting android:textIsSelectable="true" in xml for the TextView will show the native text selection popup and I’ve been using that in my application. But what I found that it is not working any more when I try to set the same attribute in a view attached to the RecyclerView.
Whenever I try to select the text the following log appears –

TextView: TextView does not support text selection. Action mode cancelled.

And I don’t know why? Why it works on other screens and not with the RecyclerView. I read multiple posts –

TextView with android:textIsSelectable="true" not working in listview

textview textIsSelectable="true" not working in Listview

android:textIsSelectable="true" for TextView inside Listview does not work

But then I encountered this post –

Android: "TextView does not support text selection. Action mode cancelled"

And the reply by @hungkk worked for me. His solution suggested the TextView width to change to wrap_content from match_parent.

I know I can do this but my question is how this fixed the issue because it looks weird to me. And also, what is the solution if I want to keep the width to match_parent.

Any inputs are welcome.


Get this bounty!!!