【发布时间】:2018-05-14 12:45:19
【问题描述】:
我正在研究将 ListView 作为列表项的 RecyclerView。 我正在为 RecyclerView 使用 LinearLayoutManager。 ListView 有大量水平和垂直滚动的数据。 但在我的情况下,在纵向模式下它会停止垂直滚动,而在横向模式下,它会停止水平滚动。要求是不可能改变的。有什么建议可以解决这个问题。我附上了我的部分代码。
列表项:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/info_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:elevation="5dp"
android:orientation="vertical"
android:visibility="visible">
<View
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="2px"
android:background="@color/table_item_even" />
<ListView
android:id="@+id/lst_info"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbars="horizontal|vertical"
android:transcriptMode="alwaysScroll"></ListView>
回收站视图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_multiprobs_info"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
LinearLayoutManager 方向改变模式:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
} else {
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
}
【问题讨论】:
-
我认为 getResources().getConfiguration().orientation 可能会返回“错误”的方向。你什么时候打电话?
-
也许尝试使用“Display getOrient = activity.getWindowManager().getDefaultDisplay();”来获取显示。然后用显示的高度和宽度构建你的 if。
-
@GAlexMES 我想你不明白这个问题。如果定向条件正常。
-
你可以考虑看看这个answer。
-
@ReazMurshed 它帮助了我
标签: android android-recyclerview