2017-05-01 7 views
0

ich versuche, app mit 2 tablayout zu erstellen ich folge ein paar schritte und alle dinge funktioniert gut, aber ich habe dieses problem mit Tablayout zeigen mir großen platz zwischen Toolbar und tablayout wie dieses foto, wenn ich scrollen tablabyout Space verschwindet ich möchte entfernen dieser Raumwarum tablayout scrollen?

enter image description here

, wenn ich nach oben:

enter image description here

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:id="@+id/drawer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
android:background="#ffffff"> 
<android.support.design.widget.CoordinatorLayout 
    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" 
     app:layout_scrollFlags="scroll|snap" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 
     <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|snap" 
      android:elevation="5dp" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_below="@id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabMaxWidth="0dp" 
      app:layout_scrollFlags="snap|enterAlways" 
      app:tabGravity="fill" 
      app:tabMode="fixed" 
      app:tabIndicatorHeight="4dp" 
      android:elevation="10dp"/> 
    </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" 
     android:background="#FFFFFF" 
     app:layout_scrollFlags="scroll|enterAlways" /> 
</android.support.design.widget.CoordinatorLayout> 

Style.xml:

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

+0

Können Sie auch Ihre Basis Thema Post von 'Style.xml' - Der leere Raum wahrscheinlich zweite Toolbar ist. Einer wird durch Ihr Thema erstellt und eines, das Sie selbst im Layout hinzufügen. – Sharj

+0

@Sharj ' ' – MrMR

+0

Ich aktualisiere meinen Beitrag – MrMR

Antwort

0

In Ihrem Fall der zusätzliche Raum ist eine Symbolleiste in Ihrem xml auf das obere Register Layout und Sie verwenden Thema

"Theme.AppCompat.Light.DarkActionBar" 

die werden zwei Aktionsleiste hier verursachen, wenn Sie nicht Toolbar verwenden, entfernen Sie es einfach

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:id="@+id/drawer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
android:background="#ffffff"> 
<android.support.design.widget.CoordinatorLayout 
    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" 
     app:layout_scrollFlags="scroll|snap" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_below="@id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabMaxWidth="0dp" 
      app:layout_scrollFlags="snap|enterAlways" 
      app:tabGravity="fill" 
      app:tabMode="fixed" 
      app:tabIndicatorHeight="4dp" 
      android:elevation="10dp"/> 
    </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" 
     android:background="#FFFFFF" 
     app:layout_scrollFlags="scroll|enterAlways" /> 
</android.support.design.widget.CoordinatorLayout> 

dies Ihre letzte xml sein, nachdem Toolbar Entfernen Sie sonst Symbolleiste wollen dann die ihnen gesetzt, die ActionBar

0

Problem nicht haben: Ich habe Ihre Manifest-Datei nicht, aber es sieht aus wie Sie eine Standard haben Toolbar kommt von Ihrem Theme und Sie setzen sich selbst ein. Um das Problem zu beheben, können Sie die Standard-Symbolleiste entfernen und die von Ihnen hinzugefügte Symbolleiste verwenden.

Um dies zu beheben, folgen Sie diesen Schritten.

Schritt 1: Fügen NoActionBar Art Ihres Style.xml

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

Schritt 2: AppTheme.NoActionBar auf Ihre Aktivität in Manifest.xml

<activity 
    android:name="YourActivity" 
    android:theme="@style/AppTheme.NoActionBar"> 
</activity> 

Ihre Aktivität hat kein System Toolbar Jetzt Set . Sie können Ihre eigenen Toolbar anpassen, wie Sie möchten.

Schritt 3: Legen Sie Ihr Layout Toolbar als Standard Toolbar innerhalb Ihrer Activity.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 

Jetzt können Sie diese Toolbar verwenden:

setTitle("Some Title");