[英]Orientation is not working in recyclerview in BottomNavigationView Fragment. Where to set orientation attribute?
I have a RecyclerView in a fragment and want to set orientation horizontal. 我在片段中有一个RecyclerView,并且想要将方向设置为水平。 But adding attribute android:orientation="horizontal"
is not working.Here are the layouts. 但是添加属性android:orientation="horizontal"
不起作用。以下是布局。
Fragment Layout: 片段布局:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/dashboardRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
Model Layout: 型号布局:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
app:cardCornerRadius="5dp"
app:cardElevation="5dp">
<TextView
android:id="@+id/textViewId"
android:layout_width="80dp"
android:layout_height="80dp"
android:padding="10dp"
android:text="@string/name"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
</android.support.v7.widget.CardView>
where should I put android:orientation="horizontal"
attribute? 我应该在哪里放置android:orientation="horizontal"
属性? Thanks 谢谢
If you want a horizontal list with recyclerview, you need to set the orientation in the LayoutManager. 如果要使用recyclerview作为水平列表,则需要在LayoutManager中设置方向。
eg: 例如:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.dashboardRecyclerView)
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
If you would rather do this in xml, you need to specify the layout manager as well in xml: 如果您希望在xml中执行此操作,则还需要在xml中指定布局管理器:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="@dimen/spacing_regular"
android:clipToPadding="false"
android:paddingTop="@dimen/spacing_regular"
android:scrollbars="none"
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
The "orientation" attribute in xml is for LinearLayout and other. xml中的“ orientation”属性用于LinearLayout等。 for a recyclerview, the orientation set by the LayoutManager Objet 对于recyclerview,由LayoutManager Objet设置的方向
in your Activity or Fragment do this for your recyclerView 在您的Activity或Fragment中为您的recyclerView执行此操作
RecyclerView yourecyclerView =RecyclerView)findViewById(R.id.dashboardRecyclerView);
LinearLayoutManager layout = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
yourecyclerView.setLayoutManager(layout);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.