方向在 BottomNavigationView 片段的 recyclerview 中不起作用。在哪里设置方向属性?
Orientation is not working in recyclerview in BottomNavigationView Fragment. Where to set orientation attribute?
我在片段中有一个 RecyclerView,我想将方向设置为水平。但是添加属性 android:orientation="horizontal"
不是 working.Here 是布局。
片段布局:
<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>
模型布局:
<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>
我应该把 android:orientation="horizontal"
属性放在哪里?谢谢
如果你想要一个带有recyclerview的水平列表,你需要在LayoutManager中设置方向。
例如:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.dashboardRecyclerView)
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
如果您希望在 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" />
xml 中的 "orientation" 属性用于 LinearLayout 和其他。对于回收视图,由 LayoutManager Objet 设置的方向
在您的 Activity 或 Fragment 中为您的 recyclerView 执行此操作
RecyclerView yourecyclerView =RecyclerView)findViewById(R.id.dashboardRecyclerView);
LinearLayoutManager layout = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
yourecyclerView.setLayoutManager(layout);
我在片段中有一个 RecyclerView,我想将方向设置为水平。但是添加属性 android:orientation="horizontal"
不是 working.Here 是布局。
片段布局:
<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>
模型布局:
<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>
我应该把 android:orientation="horizontal"
属性放在哪里?谢谢
如果你想要一个带有recyclerview的水平列表,你需要在LayoutManager中设置方向。
例如:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.dashboardRecyclerView)
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
如果您希望在 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" />
xml 中的 "orientation" 属性用于 LinearLayout 和其他。对于回收视图,由 LayoutManager Objet 设置的方向
在您的 Activity 或 Fragment 中为您的 recyclerView 执行此操作
RecyclerView yourecyclerView =RecyclerView)findViewById(R.id.dashboardRecyclerView);
LinearLayoutManager layout = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
yourecyclerView.setLayoutManager(layout);