2016-09-17 30 views
0

即時垂直結合試圖使用2點回收的觀點在1個線性佈局.. 作爲回收視圖將產生其自己的滾動,但其他數據保留在屏幕上完整..所以如何合併所有進入1個滾動enter code here如何將多個回收視圖帶有滾動在1個線性佈局

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@color/grey" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:weightSum="100"> 

      <LinearLayout 
       android:id="@+id/sliderhome" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="70"> 


       <com.daimajia.slider.library.SliderLayout 
        android:id="@+id/slider" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        app:layout_scrollFlags="scroll|enterAlways" 
        /> 
       <com.daimajia.slider.library.Indicators.PagerIndicator 
        android:id="@+id/custom_indicator" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        /> 

      </LinearLayout> 

      <LinearLayout 
       android:layout_weight="30" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 

       <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:tools="http://schemas.android.com/tools" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        tools:context="vlabs.chorbazaar.HomeFragment" 
        android:background="@color/white" 
        android:orientation="horizontal"> 

        <android.support.v7.widget.RecyclerView 
         android:id="@+id/recycler_view" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"/> 

       </FrameLayout> 
      </LinearLayout> 
    </LinearLayout> 

我嘗試讓我的滑塊和回收以滾動爲一體的...但滑塊是停留在一個固定的地方,同時回收視圖scorlls像往常一樣

回答

0

更改xml文件:

<?xml version="1.0" encoding="utf-8"?><LinearLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="@color/grey" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:weightSum="100"> 

<LinearLayout 
    android:id="@+id/sliderhome" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="70"> 


    <com.daimajia.slider.library.SliderLayout 
     android:id="@+id/slider" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_scrollFlags="scroll|enterAlways" 
     /> 
    <com.daimajia.slider.library.Indicators.PagerIndicator 
     android:id="@+id/custom_indicator" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     /> 

</LinearLayout> 

<LinearLayout 
    android:layout_weight="30" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/view_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
</LinearLayout> 

viewpager適配器:

private class MyPagerAdapter extends FragmentPagerAdapter { 
    ArrayList<String> arrayList 
    public MyPagerAdapter(FragmentManager fm, ArrayList<String> arrayList) { 
     super(fm); 
     this.arrayList = arrayList; 
    } 

    @Override 
    public Fragment getItem(int pos) { 
     switch(pos) { 

     case 0: return FirstFragment.newInstance(arraylist); 
     case 1: return SecondFragment.newInstance(arraylist); 
    } 

    @Override 
    public int getCount() { 
     return 2; 
    }  
} 

}

在activty

ViewPager pager = (ViewPager) findViewById(R.id.viewPager); 
pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), arrayList)); 

片段在XML文件:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 


     <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</LinearLayout> 
+0

即時通訊使用片段..因此,假設上面的代碼是我的家庭碎片..我改變了我的家庭碎片xml,如你所說..爲Mypageadapter ..做了一個類.. now ViewPager pager =(ViewPager)findViewById (R.id.viewPager); pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(),arrayList)); 這段代碼會去嗎?在我的主要活動中,我根據nav –

+0

中的選擇調用了所有片段,什麼是陣列列表? –

+0

arrayList中的數據發送分片ArrayList > arrayList = new ArrayList >(); ArrayList arrayFirst = new ArrayList <>(); arrayFirst.add(「one」); arrayFirst.add(「two」); ArrayList arraySound = new ArrayList <>(); arraySound.add(「three」); arraySound.add(「four」); arrayList.add(arrayFirst); arrayList.add(arraySound); –

相關問題