2016-08-09 69 views
-2

我必须在单个活动中同时滚动水平列表视图和垂直列表视图。在单个活动中滚动两个水平列表视图和一个垂直列表视图

下面我已经发布了一个截图:

enter image description here

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_horizo​​ntal_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.It试过不可能scroll.Let我知道有没有其他的办法来解决这个问题。

如果我将垂直列表视图滚动到顶部,它只是滚动垂直列表视图。如果我将水平列表视图滚动到顶部,则滚动垂直和水平listivew.But当我拼凑起来时,水平列表视图是隐藏的。

+0

使用'android.support.v4.widget.NestedScrollView'到位'ScrollView' – JavaGhost

+1

使用recyclerview更好的滚动控制。 http://blog.inapptext.com/recyclerview-creating-dynamic-lists-and-grids-in-android-1/ –

+0

@JavaGhost它不解决。如果我滚动垂直列表视图顶部,它是滚动垂直只有列表视图。如果我将水平列表视图滚动到顶部,它将滚动垂直和水平listivew.But当我拼凑起来时,水平列表视图是隐藏的。 – Steve

回答

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> 
相关问题