我必须在单个活动中滚动水平列表视图和垂直列表视图。
下面我发布了截图:
activity_main.xml中:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/home_layout_top"
android:scrollbars="none"
>
<RelativeLayout
android:id="@+id/rl_container_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="@+id/inc_ads_horizon"
layout="@layout/ads_horizontal_listview_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp" />
<include
android:id="@+id/inc_people_know"
layout="@layout/people_you_know_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/inc_ads_horizon"
android:layout_marginTop="10dp" />
<include
android:id="@+id/inc_listview"
layout="@layout/tab_home_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/inc_people_know"
android:layout_marginTop="10dp" />
<TextView
android:id="@+id/no_user_posts_item_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/txt_no_posts_available"
android:textColor="@color/txt_common_black"
android:textSize="@dimen/txt_size" />
</RelativeLayout>
</ScrollView>
tab_home_list_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_layout_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<ListView
android:id="@+id/lv_post_home_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="@null"
android:dividerHeight="5dp"
android:scrollbars="none"
android:transcriptMode="alwaysScroll"
android:visibility="gone" />
</LinearLayout>
ads_horizontal_listview_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_horizontalscroll_child"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="@+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="@+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
people_you_know_layout.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_horizontalscroll_second_child"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="@+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
我尝试使用scrollview。它无法滚动。让我知道有没有其他方法可以解决这个问题。
如果我将垂直列表视图滚动到顶部,它只滚动垂直列表视图。如果我将水平列表视图滚动到顶部,则滚动垂直和水平listivew.But当我匍匐时,水平列表视图被隐藏。< / p>
答案 0 :(得分:0)
您可以通过自定义ScrollView
&amp;来获得所需的观看次数。 HorizontalScrollView
。
可以查看此帖子https://arunbadole1209.wordpress.com/2011/10/03/how-to-make-simultaneous-scrollable-views-in-android/
答案 1 :(得分:0)
使用此xml布局,根据实际需要自定义项目视图:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:nestedScrollingEnabled="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- You can define layout manager here also-->
<android.support.v7.widget.RecyclerView
android:id="@+id/ads_horizon"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/people_know"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/post_home_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>