2016-07-13 12 views
-1

私はAndroid Appを作成したいと思います。私のメイン画面では、タブ付きアクティビティを使用します。私が望むように見える。しかし、私はScrollViewと私のTextViewを囲むときにのみ、テキストをスクロールし、それは次のようになります。私はスクロールする前にAndroidタブ付きアクティビティスクロール

をだからになります

So it should look before I scroll

そして、このように私はスクロールした後:ここで

And like this after I scrolled

タブの活動です:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/appbar_padding_top" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <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/AppTheme.PopupOverlay"> 

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

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

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

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="end|bottom" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_dialog_email" /> 

そして、ここにテキスト断片:

<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:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.obware.story.Activitys.MainActivity$PlaceholderFragment"> 

<TextView 
    android:id="@+id/section_label" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

は、誰もが、私はそれを行うことができます方法を知っていますか?

+0

コードを記入してください。 –

+0

私はいくつかを追加しました – user3050346

+0

[アンドロイドロリポップツールバーの重複の可能性:スクロール中にツールバーを隠す/表示する方法は?](http://stackoverflow.com/questions/26539623/android-lollipop-toolbar-how-to-hide -show-the-toolbar-while-scrolling) – Kushan

答えて

0

これはTablayoutなので、私はあなたがフラグメントとViewPagerを使用していると仮定しています。 (これはビューページがなくてもまだ適用されます)

この場合、ツールバーを非表示にするための基礎となるアクティビティを送信する必要があります。 Tabレイアウトを持つ基本アクティビティ内のインターフェイスを宣言します。

は言う:

interface HideToolBarInterface{ 

    public void hideTheToolbar(boolean shouldbehidden); 
} 

今すぐあなたの活動の内側に、このインタフェースを実装し、宣言した抽象メソッドを書き換えて。

例えば:あなたの断片内部の今

public void hideTheToolbar(boolean shouldbehidden){ 
if(shouldbehidden){ 
    getSupportActionBar().hide(); // if you have set your own toolbar, hide it similarly 
}else{ 
    getSupportActionBar().show(); 
} 
} 

、あなたがリストを表示するために使用しているものは何でもあなたのリストビューまたはRecyclerViewにonScrollListenerを設定します。

//on some condition(say SCROLL_STATE_FLING) do the following: 
((HideToolbarInterface)getActivity()).hideTheToolbar(true); 

//on some other conditon(say SCROLL_STATE_IDLE unhide it: 
((HideToolbarInterface)getActivity()).hideTheToolbar(false); 

あなたがここに他のオプションを確認することができます:

リストがスクロールされたときに

は今、あなたのようなツールバーを非表示にするインターフェイスメソッドを呼び出すために、リスナーがonScrollChanged使用あなたのロジックを適用することができます

android lollipop toolbar: how to hide/show the toolbar while scrolling?

関連する問題