Hide AppBar when scrolling down

后端 未结 7 1956
小蘑菇
小蘑菇 2020-12-02 18:10

I have an AppBar and a horizontal linearlayout (which includes an edit text and two imagebuttons) and other things in my layout. When user scrolls down,

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 18:22

    In the Drawer.Layout add in android:fitsSystemWindows="true".

    
    

    It's better to separate out your concerns. Using the sample provided by chrisbanes/cheesesquare, your layout would be better looking like this:

    
    
    
    
    
    
        
    
    
    
    
    
    
    

    Replace this:

        
        
        
        
            
        
        
        
        
        
    

    With

    
    

    And then use the ViewPager to populate your list.

     ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        if (viewPager != null) {
            setupViewPager(viewPager);
        }
    
    private void setupViewPager(ViewPager viewPager) {
        Adapter adapter = new Adapter(getSupportFragmentManager());
        adapter.addFragment(new CheeseListFragment(), "Category 1");
        adapter.addFragment(new CheeseListFragment(), "Category 2");
        adapter.addFragment(new CheeseListFragment(), "Category 3");
        viewPager.setAdapter(adapter);
    }
    

    Then you can format this CheeseListFragment to add your image views individually.

    It's also unnecessary to keep declaring your schema:

    xmlns:app="http://schemas.android.com/apk/res-auto"
    

    This is an indicator that you are copying and pasting code and not understanding it.

    You should also be using a nestedScrollView without the view, and linear layout above it. Mind you, it's not clear what you are trying to acheive with that.

提交回复
热议问题