Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

java - 如何在代码中设置setReverseLayout()?(How do I set setReverseLayout() in my code?)

I wanted to create Reverse Order in my recyclerview.

(我想在recyclerview中创建逆向订单。)


     recyclerView = findViewById(R.id.rv);
     recyclerView.setHasFixedSize(true);
     recyclerView.setLayoutManager(new LinearLayoutManager(this).setReverseLayout(true));

 <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:padding="5dp"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:reverseLayout="true"
            app:stackFromEnd="true"/>

But I got error that said setLayoutManager cannot be applied (void)

(但是我收到一个错误,说无法应用setLayoutManager(无效))

this is what I have tried

(这就是我尝试过的)

  ask by last gg translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try this:

(尝试这个:)

 LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, true);// the last parameter (true) means Reverse be enable or not
 recyclerview.setLayoutManager(layoutManager);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...