2016-04-02 16 views
2

イメージごとにしたい。これは基本的レイアウトアーキテクチャ:ヘッダーとViewPagerのtablayoutを使用

  1. 画面 - フルエリアがスクロール可能です。 topは、水平スクロールが存在するレイアウトです。タブレイアウトとビューページャー

    2.Screen - ユーザーが下にスクロールすると、水平スクロールのヘッダー部分が表示され(上には表示されません)、タブレイアウトは常に上に表示され、ビューページャー再び彼はその後、トップヘッダが

を来るべきでスクロールアップスワップ可能.butは、I REFはこのhttps://github.com/kmshack/Android-ParallaxHeaderViewPagerが、そのない私の必要性につきとして

答えて

1

このライブラリを試してみてください:

https://github.com/noties/Scrollable

私はそれはあなたが欲しいものだと思います。

+0

これで、ユーザーがスワイプしてtablayoutをスティッキーヘッダーとしてツールバーを隠すことができます – andro

+0

@アンドロムこのような効果が必要な場合はCoordinatorLayoutを試すことができます。 –

0

activity_tab_layout.xml午前です

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:background="@color/colorPrimary" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapse_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/material_deep_teal_500" 
     android:fitsSystemWindows="true" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

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

     <!--<android.support.v7.widget.Toolbar--> 
       <!--android:id="@+id/toolbar"--> 
       <!--android:layout_width="match_parent"--> 
       <!--android:layout_height="?attr/actionBarSize"--> 
       <!--android:background="?attr/colorPrimary"--> 
       <!--app:layout_scrollFlags="scroll|enterAlways"--> 
        <!--app:popupTheme="@style/ThemeOverlay.AppCompat.Dark">--> 

       <!--</android.support.v7.widget.Toolbar>--> 

      <HorizontalScrollView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

      </HorizontalScrollView> 


      </LinearLayout> 

     </LinearLayout> 
    </android.support.design.widget.CollapsingToolbarLayout> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:foregroundGravity="center_horizontal" 
     app:layout_collapseMode="pin" 
     app:tabGravity="center" 
     app:tabMode="scrollable" 
     app:tabSelectedTextColor="@color/colorAccent" 
     app:tabTextColor="@color/colorPrimary" /> 

</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

ActivityCode.java

public class ActivityCode extends AppCompatActivity { 

    TabLayout tabs; 
    ViewPager viewPager; 

    Toolbar toolbar; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_cancer_type); 

// your find view by id code 

     toolbar.setTitle(title); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setHomeButtonEnabled(true); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

     setupViewPager(viewPager); 
     tabs.setupWithViewPager(viewPager); 
    } 


    private void setupViewPager(ViewPager viewPager) { 

     ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); 

     Fragment facts = new FRAGMENT_CLASS(); 
     adapter.addFragment(facts, "Title"); 
    Fragment facts = new FRAGMENT_CLASS(); 
     adapter.addFragment(facts, "Title"); 
    Fragment facts = new FRAGMENT_CLASS(); 
     adapter.addFragment(facts, "Title"); 


     viewPager.setAdapter(adapter); 
    } 

    public class ViewPagerAdapter extends FragmentPagerAdapter { 
     private final List<Fragment> mFragmentList = new ArrayList<>(); 
     private final List<String> mFragmentTitleList = new ArrayList<>(); 

     public ViewPagerAdapter(FragmentManager manager) { 
      super(manager); 
     } 

     @Override 
     public Fragment getItem(int position) { 
      return mFragmentList.get(position); 
     } 

     @Override 
     public int getCount() { 
      return mFragmentList.size(); 
     } 

     public void addFragment(Fragment fragment, String title) { 
      mFragmentList.add(fragment); 
      mFragmentTitleList.add(title); 
     } 

     @Override 
     public CharSequence getPageTitle(int position) { 
      return mFragmentTitleList.get(position); 
     } 
    } 
    } 
+0

xmlが適切でない – andro

+0

@andro appcompatv7とアンドロイドデザインライブラリをコンパイルする必要があります。 –

関連する問題