自定义视图你好,我是用可折叠的布局,我想,如下图所示布局根据我的滚动事件改变的行为:可折叠布局与安卓
- 这是默认图像与列表视图和用户滚动时,顶部布局应该改变,看起来像第二个图像。
我应该如何实现这种使用可折叠布局行为。
自定义视图你好,我是用可折叠的布局,我想,如下图所示布局根据我的滚动事件改变的行为:可折叠布局与安卓
- 这是默认图像与列表视图和用户滚动时,顶部布局应该改变,看起来像第二个图像。
我应该如何实现这种使用可折叠布局行为。
你只需要添加TabLayout工具栏下,像下面
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayoutactivity_mainId"
android:layout_below="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
我不想要标签布局。标签布局将保持不变,但工具栏正在被替换,请参阅第二张图片。 –
我无法理解你在说什么..,我正在使用上述布局作为我的一个应用程序开发 – Sam
尝试重写此acording您的需要。您可以在CollapsableToolbar中设置制作可见/隐藏组件的布局。
appbar = (AppBarLayout) findViewById(R.id.appbar);
header = (Toolbar) findViewById(R.id.toolbar);
appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
private State state;
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (verticalOffset == 0) {
if (state != State.EXPANDED) {
collapsingToolbar.setTitleEnabled(false);
// do something here
}
state = State.EXPANDED;
} else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
if (state != State.COLLAPSED) {
collapsingToolbar.setTitle("All Jobs ");
collapsingToolbar.setTitleEnabled(true);
// do something here header.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.actionbar_gradient));
// collapsingToolbar.setContentScrim(ContextCompat.getDrawable(this, R.drawable.actionbar_gradient));
collapsingToolbar.setContentScrim(ContextCompat.getDrawable(this, R.drawable.actionbar_bg));
// collapsingToolbar.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.actionbar_bg));
}
state = State.COLLAPSED;
} else {
if (state == State.IDLE) {
collapsingToolbar.setTitleEnabled(false);
container.setVisibility(View.VISIBLE);
}
state = State.IDLE;
}
}
});
它为我试试吧....
什么你到目前为止已经试过? –