2016-10-06 8 views
1

私はタブをブラウズするためにViewpagerを使用しています。しかし、私のビューページはフラグメントの上端と重複しています。そのため、すべてのファジィのトップが見えません。上部にパディングを追加すると作業はできますが、次のビューでパディングを行うよりも、パディングを行う方が良い方法があります。ページャが縦方向にタブフラグメントをオーバーラップしています

レイアウト

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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=".Activity.MainActivity"> 

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

    <android.support.design.widget.TabLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/tabs"> 
    </android.support.design.widget.TabLayout> 

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


<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="#ffffff"> 

</android.support.v4.view.ViewPager> 

</RelativeLayout> 

活動

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // ActionBar 

    final ActionBar actionBar = getSupportActionBar(); 
    actionBar.setDefaultDisplayHomeAsUpEnabled(true); 


    // ViewPage: Slider that helps to create a page that we can swipe 
    PagerAdapter pagerAdapter = new TabPagerAdapter(getSupportFragmentManager()); 
    ViewPager tab = (ViewPager) findViewById(R.id.pager); 

    tab.setAdapter(pagerAdapter); 

    //Tablayout : Shows the tab bar that helps to find the ViewPager page 
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); 
    tabLayout.setupWithViewPager(tab); 

} 
+0

。あなたはどのようなレイアウトを持っていますか?それらを両方とも線形レイアウトに入れることができます。 –

+0

相対的なレイアウト –

+0

@SaprativeJana私の答えをチェックしてください。あなたの問題を解決してくれることを願っています。 –

答えて

0

あなたは相対的なレイアウトを使用してアンドロイドを定義していない:layout_below = "@のID/appbar_layout"。だからあなたのコードを編集しました。 あなたのxmlファイルにコードをコピーして貼り付けてください。あなたの問題を解決します。これはあなたを助けることができる

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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"> 

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

    <android.support.design.widget.TabLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/tabs"> 
    </android.support.design.widget.TabLayout> 

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


<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/appbar_layout" 
    android:orientation="vertical" 
    android:background="#ffffff"> 

</android.support.v4.view.ViewPager> 

</RelativeLayout> 
+0

私はそれを試しました。しかしそれは何の違いもありません –

+0

@SaprativeJana私はXMLコードで自分の答えを編集しました。 –

1

希望..私はあなたが全体のXMLを示していない推測している

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/coordinator" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

     <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" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tablayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      app:tabGravity="fill" /> 

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

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

関連する問題