我正在使用ScrollView,我在其中使用RelativeLayout,其中我在HorizontalScrollView中使用ListView。现在之后,我正在放置一个按钮,但由于页面没有滚动而无法滚动到该按钮,只有ListView正在滚动。
我希望列表滚动,列表完成后页面应滚动,以便我可以看到按钮点击它
怎么做
我正在分享我到目前为止制作的xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/heading2"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:text="Horizontal List View"
android:textSize="30dp"
android:textStyle="bold"
android:focusable="true"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="370dp"
android:id="@+id/hori_scroll_view"
android:layout_below="@+id/heading2"
android:layout_marginTop="20dp">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"/>
</HorizontalScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/page2"
android:layout_below="@+id/hori_scroll_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Next" />
</RelativeLayout>
</ScrollView>
答案 0 :(得分:0)
您可以使用RecyclerView
执行此操作<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/heading2"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:text="Horizontal List View"
android:textSize="30dp"
android:textStyle="bold"
android:focusable="true"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="370dp"
android:layout_below="@+id/heading2"
android:layout_marginTop="20dp"
android:scrollbars="horizontal"
android:id="@+id/list"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/page2"
android:layout_below="@+id/list"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Next" />
</RelativeLayout>
</ScrollView>
然后在您的活动中添加此内容,
LinearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView myList = findViewById(R.id.list);
myList.setLayoutManager(layoutManager);
答案 1 :(得分:0)
您是否尝试使用列表视图水平/垂直滚动?如果您尝试垂直滚动,则必须使用NestedScrollView和RecyclerView。