Android 顶部悬停
16lz
2021-01-23
效果主要靠布局来实现的,主要使用了CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout
<?xml version="1.0" encoding="utf-8"?>.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> .support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> .support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:layout_collapseMode="parallax" app:layout_collapseParallaxMultiplier="0.7" app:layout_scrollFlags="scroll|exitUntilCollapsed"> "match_parent" android:layout_height="match_parent" android:src="@drawable/wenyi" /> .support.design.widget.CollapsingToolbarLayout> .support.design.widget.TabLayout android:id="@+id/tablayout" android:layout_width="match_parent" android:layout_height="wrap_content"> .support.design.widget.TabLayout> .support.design.widget.AppBarLayout> .support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior"> "match_parent" android:layout_height="wrap_content" android:text="@string/str" android:textSize="20sp" /> .support.v4.widget.NestedScrollView>.support.design.widget.CoordinatorLayout>
Activity里面主要就是对TabLayout 的设置
private TabLayout mTabLayout; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_coor); mTabLayout= (TabLayout) findViewById(R.id.tablayout); mTabLayout.addTab(mTabLayout.newTab().setText("分类")); mTabLayout.addTab(mTabLayout.newTab().setText("排序")); mTabLayout.addTab(mTabLayout.newTab().setText("价格")); mTabLayout.setTabTextColors(Color.BLACK,Color.RED); mTabLayout.setSelectedTabIndicatorColor(Color.RED); mTabLayout.setBackgroundColor(Color.GREEN); }
更多相关文章
- android启动和推出实现侧滑效果
- Android 滑动效果代码分享
- Android之给图片添加水印效果
- android表格效果--ListView隔行变色
- android动态布局方法总结
- android短信窃听器,娱乐版,效果可以实现
- Android——布局的一些动态设置