Comments (2)
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
android:fitsSystemWindows="true"
app:statusBarBackground="@android:color/transparent">
<!--AppBarLayout必须设置固定高度-->
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_behavior="@string/appbar_spring_behavior">
<!--设置可滚动并且折叠在顶部-->
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:contentScrim="@color/transparent"
app:layout_scrollFlags="exitUntilCollapsed|scroll"
app:statusBarScrim="@color/transparent">
<ImageView
android:id="@+id/bg_layer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="fitXY"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="parallax" />
<!--坑爹的google,pin模式只能在toolbar上生效-->
<!--如果使用其他viewGroup包裹的情况下,toolbar-->
<!--会被折叠-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/pink"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/left_component"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foregroundGravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread">
<ViewStub
android:id="@+id/left_stub"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/left_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textStyle="bold" />
</FrameLayout>
<TextView
android:id="@+id/title_component"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#252122"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/right_component"
app:layout_constraintStart_toStartOf="@+id/left_component"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteY="19dp" />
<FrameLayout
android:id="@+id/right_component"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5">
<TextView
android:id="@+id/right_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:text="" />
<ViewStub
android:id="@+id/right_stub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right" />
</FrameLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.TabLayout
android:id="@+id/toolbar_tab"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="#ffffff"
app:layout_collapseMode="pin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_scrollFlags="scroll|enterAlways"
app:tabIndicatorColor="#0835f8"
app:tabIndicatorHeight="2.0dp"
app:tabSelectedTextColor="#0835f8"
app:tabTextColor="#ced0d3">
<android.support.design.widget.TabItem
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="分享" />
<android.support.design.widget.TabItem
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="收藏" />
<android.support.design.widget.TabItem
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="关注" />
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/main_vp_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/pink"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar_tab" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
from appbarlayout-spring-behavior.
package com.aihuawen.erwin.mvp.view.activity
import android.graphics.Color
import android.os.Build
import android.support.design.widget.AppBarLayout
import android.support.v7.widget.Toolbar
import android.util.TypedValue
import android.view.WindowManager
import android.widget.TextView
import com.aihuawen.erwin.R
import com.aihuawen.erwin.base.context.BaseActivity
import com.aihuawen.erwin.mvp.contract.SpecialSubjectContract
import com.aihuawen.erwin.mvp.presenter.SpecialSubjectPresenter
import com.aihuawen.erwin.utils.GlideUtil
import com.aihuawen.erwin.utils.doOnBackPressedEvent
import com.huawen.baselibrary.views.drawableRes
import com.huawen.baselibrary.views.layoutParamsMargin
import org.jetbrains.anko.dip
class SpecialSubjectActivity : BaseActivity<SpecialSubjectContract.View, SpecialSubjectContract.Presenter>(), SpecialSubjectContract.View {
override fun getLayoutId() = R.layout.activity_subject
override fun configView() {
find<TextView>(R.id.left_txt)?.drawableRes(left = R.drawable.icon_back)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
var statusBarHeight = -1
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
if (resourceId > 0) {
//根据资源ID获取响应的尺寸值
statusBarHeight = resources.getDimensionPixelSize(resourceId)
}
var actionBarHeight = 0
// Calculate ActionBar height
try {
val tv = TypedValue()
if (theme.resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, resources.displayMetrics)
}
} catch (e: Exception) {
e.printStackTrace()
}
val total = statusBarHeight + actionBarHeight
find<Toolbar>(R.id.toolbar)?.setPadding(0, statusBarHeight, 0, 0)
find<Toolbar>(R.id.toolbar)?.layoutParams?.height = total
}
//设置toolbar
setSupportActionBar(find(R.id.toolbar))
doOnBackPressedEvent(find<TextView>(R.id.left_txt))
find<TextView>(R.id.right_txt)!!.layoutParamsMargin(right = dip(10))
find<TextView>(R.id.left_txt)!!.layoutParamsMargin(dip(10))
find<TextView>(R.id.right_txt)!!.drawableRes(R.drawable.icon_share)
GlideUtil.intoView(find(R.id.bg_layer), "http://pic166.nipic.com/file/20180518/8429994_112007730037_2.jpg")
val appBar = find<AppBarLayout>(R.id.appBar)
appBar?.addOnOffsetChangedListener(object : AppBarLayout.OnOffsetChangedListener {
override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) {
find<Toolbar>(R.id.toolbar)?.setBackgroundColor(changeAlpha(resources.getColor(R.color.white),
Math.abs(verticalOffset * 1.0f) / (appBarLayout?.totalScrollRange ?: 1)))
}
})
// val tabScrimHelper = TabScrimHelper(find(R.id.toolbar_tab), find(R.id.toolbarLayout)){
// appBarLayout, verticalOffset ->
// find(R.id.toolbar)?.setBackgroundColor(changeAlpha(resources.getColor(R.color.white),
// Math.abs(verticalOffset * 1.0f) / (appBarLayout?.totalScrollRange ?: 1)))
// }
// appBar?.addOnOffsetChangedListener(tabScrimHelper)
}
/** 根据百分比改变颜色透明度 */
fun changeAlpha(color: Int, fraction: Float): Int {
val red = Color.red(color)
val green = Color.green(color)
val blue = Color.blue(color)
val alpha = (Color.alpha(color) * fraction).toInt()
return Color.argb(alpha, red, green, blue)
}
override fun initData() {
}
override fun initPresenter() = SpecialSubjectPresenter()
override fun showError(e: Throwable) {
}
override fun complete() {
}
}
from appbarlayout-spring-behavior.
Related Issues (20)
- 最小SDK 怎么不支持15,而是17?
- Spring with Tab AppbarLayout 有滑动冲突现象
- Not support design:27.1.1 not MathUtil HOT 2
- 我项目中使用的RecyclerView 但是没有数据时 需要显示一个错误页面,但是不是剧中的 请问楼主怎么如何解吗 HOT 2
- 我尝试设置默认header的高度,基本无效,请问如何修改header默认高度
- There is no setCollapsedState() in AppBarLayout HOT 1
- fragment完全没法用 HOT 2
- 28.0.0的有问题 HOT 2
- There is no support for androidx HOT 1
- supportLibraryVersion=28.0.0适配问题解决 HOT 1
- 支持下SDK 28 和Androidx
- 不支持CollapsingToolbarLayout里面嵌套布局 HOT 2
- Gradle error HOT 7
- Gradle Building Error HOT 3
- androidx HOT 1
- 没法实现 下拉图片放大的效果呀。。。是我哪里用错了了吗? HOT 1
- androidX 1.0.8 hint HOT 2
- 不维护了吗 HOT 4
- Any updates?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from appbarlayout-spring-behavior.