Android悬浮title实现

步骤:

    1.将需要悬浮的layout放到CollapsingToolbarLayout之外,AppBarLayout之内
    2.将CollapsingToolbarLayout的app:layout_scrollFlags设置为scroll
    3.给NestedScroolView设置app:layout_behavior="@String/appbar_scrolling_view_behavior"就大功告成了(根布局一定要是CoordinatorLayout)
xml文件



    

        

            
        

        
    

    

        
    

java代码
public class ThirdActivity extends AppCompatActivity {
    private ListView lv;
    private List list;

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

        lv = (ListView) findViewById(R.id.lv);
        list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            list.add("第" + (i + 1) + "项数据!");
        }
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list);
        lv.setAdapter(adapter);
    }
}

你可能感兴趣的:(Android悬浮title实现)