kHRYSTAL / CircleRecyclerView

the library is a loop RecyclerView(expression), can show some effects when display
714 stars 100 forks source link

CircularViewRTLMode get selected value #24

Closed gagan50 closed 6 years ago

gagan50 commented 6 years ago

Please let us know how i can get selected value and scoll list on click to next item and code below of CircularViewRTLMode.

@Override public void applyToView(View v, RecyclerView parent) { float halfHeight = v.getHeight() 0.5f; float parentHalfHeight = parent.getHeight() 0.5f; float y = v.getY(); float rot = parentHalfHeight - halfHeight - y; Log.e("paent", "applyToView:>>"+parent.getChildAdapterPosition(v) ); ViewCompat.setPivotX(v, v.getWidth()); ViewCompat.setPivotY(v, halfHeight); ViewCompat.setRotation(v, -1 rot 0.05f); ViewCompat.setTranslationX(v, -1 (float) (-Math.cos(rot mTranslationRatio mDegToRad) + 1) mCircleOffset);

    float scale = 1.0f - Math.abs(parentHalfHeight - halfHeight - y) * mScalingRatio;
    ViewCompat.setScaleX(v, scale);
    ViewCompat.setScaleY(v, scale);
}
kHRYSTAL commented 6 years ago

in branch #12 add CurrentItemCallback in class CircleRecyclerView, in CircularViewRTLMode can't get selected value and scoll list on click to next item, you can add setCurrentItemCallback, get the center selected value, and if you want get other item value when click, you can add itemView.setOnClickListener(yourListener) in onBindViewHolder, and CurrentItemCallback#onItemInCenter will also called

notice

this branch not merge to master, you can watch the sample Issue12Activity.java and CircleRecyclerView.java in branch #12

kHRYSTAL commented 6 years ago

and if you want other item support click, do not add setOnCenterItemClickListener

gagan50 commented 6 years ago

Hell sir/ma'am

Please provide code for get selected value

gagan50 commented 6 years ago

is there anyway to get value that has been set after scroll the wheel in circularRTL becuase i'am using that one

kHRYSTAL commented 6 years ago

@gagan50 this commit is the code how to get select value

pls watch the branch

gagan50 commented 6 years ago

is there any way to get selected value in curcularViewRTLMode?

kHRYSTAL commented 6 years ago

@gagan50 get selected value not dependence the child class of ItemViewMode, and I write the CurrentItemCallback is in the CircleRecyclerView, it's adapted all of ItemViewMode

gagan50 commented 6 years ago

i have an arraylist

ArrayList arrayList = new ArrayList<>(); arrayList.add(0, "Mandarian"); arrayList.add(1, "Spanish"); arrayList.add(2, "English"); arrayList.add(3, "Arabic"); arrayList.add(4, "Portuguese"); arrayList.add(5, "Russian"); arrayList.add(6, "Thai ");

mCircleRecyclerView.setCurrentItemCallback(new CurrentItemCallback() {

@Override
public void onItemInCenter(View centerItem) {
    Log.e("onItemInCenter", "onItemInCenter:>>center" );

    int position = (int) centerItem.getTag(R.string.item_position);

    position = position % arrayList.size();
    Log.e("LENGTH_SHORT", "onItemInCenter:>>>>>>>"+position);

}

});

while run it's crash java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference

kHRYSTAL commented 6 years ago

pls watch my whole commit you need holder.itemView.setTag(R.string.item_position, position); in onBindViewHolder at first

gagan50 commented 6 years ago

Hello sir/ma'm

Thank you so much for such patience and guideline. Successfully its working

gagan50 commented 6 years ago

may i know that how i can start scroll list from first position

kHRYSTAL commented 6 years ago

@gagan50 in current version not support scroll from first position, because, it's conflict with findViewAtCenter

but you can write like this after recyclerView.setAdapter()

mCircleRecyclerView.post(new Runnable() {
            @Override
            public void run() {
                mCircleRecyclerView.scrollBy(0, -mCircleRecyclerView.getHeight()/2 + mCircleRecyclerView.getChildAt(0).getHeight()/2);
            }
        });

and this is a hack method

gagan50 commented 6 years ago

i have write after set adapter it's send exception i.e

java.lang.NullPointerException: Attempt to invoke virtual method 'int

android.view.View.getHeight()' on a null object reference

kHRYSTAL commented 6 years ago

you need must ensure the adapter have datas, and you have to use mCircleRecyclerView.post() to ensure the itemView is display on screen before execute mCircleRecyclerView.scrollBy, also, if you know the itemView height, you can write the fixed value to replace mCircleRecyclerView.getChildAt(0).getHeight()

gagan50 commented 6 years ago

I have implemented below code please review

ArrayList arrayList=new ArrayList<>(); arrayList.add(0, "Mandarian"); arrayList.add(1, "Spanish"); arrayList.add(2, "English"); arrayList.add(3, "Arabic"); arrayList.add(4, "Portuguese"); arrayList.add(5, "Russian"); arrayList.add(6, "Thai ");

    mCircleRecyclerView.setAdapter(new A(arrayList));

    mCircleRecyclerView.post(new Runnable() {
        @Override
        public void run() {
            mCircleRecyclerView.scrollBy(0,

-mCircleRecyclerView.getHeight()/2 + mCircleRecyclerView.getChildAt(0).getHeight()/2); } });

kHRYSTAL commented 6 years ago

@gagan50 yes i thought it works

gagan50 commented 6 years ago

but sir it through exception

kHRYSTAL commented 6 years ago

you can test your code in my sample menu item NOLOOPBUTCENTER, i test it works

gagan50 commented 6 years ago

ok let me know that how i can change color of selected item

MaosanDao commented 5 years ago

@gagan50 this commit is the code how to get select value

pls watch the branch

作者你好,这个回调会触发多次,怎么解决?