滚动recyclelerview时如何在状态栏下完全隐藏工具栏

时间:2016-01-04 12:32:27

标签: java android xml android-recyclerview toolbar

我尝试为Google Photo中体现的工具栏滚动行为。但是我的工具栏没有完全隐藏在状态栏下。

enter image description here

enter image description here

enter image description here

if(itLogger != mLoggerMap.end()){
    return itLogger->second.get();
}

2 个答案:

答案 0 :(得分:0)

查看此库Android-ObservableScrollView

Whatsapp使用相同的

答案 1 :(得分:0)

我使用此代码隐藏工具栏,您可以从下面的代码编写中获取帮助。

    public class MainActivity extends AppCompatActivity implements ObservableScrollViewCallbacks{


    @Override
    public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {

    }

    @Override
    public void onDownMotionEvent() {

    }

    @Override
    public void onUpOrCancelMotionEvent(ScrollState scrollState) {
        ActionBar ab = getSupportActionBar();
        if (scrollState == ScrollState.UP) {
            if (ab.isShowing()) {
                ab.hide();
             //   image.setVisibility(View.GONE);
            }
        } else if (scrollState == ScrollState.DOWN) {
            if (!ab.isShowing()) {
                ab.show();
             //   image.setVisibility(View.VISIBLE);
            }
        }

    }

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

      //  image = (ImageView) findViewById(R.id.image);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ObservableListView listView = (ObservableListView) findViewById(R.id.list);
        listView.setScrollViewCallbacks(MainActivity.this);

        ArrayList<String> items = new ArrayList<String>();
        for (int i = 1; i <= 100; i++) {
            items.add("Item " + i);
        }
        listView.setAdapter(new ArrayAdapter<String>(
                this, android.R.layout.simple_list_item_1, items));


    }
  }