android中带有自定义视图的可折叠布局
您好,我正在使用可折叠布局,我希望布局的行为根据我的滚动事件进行更改,如图所示:android中带有自定义视图的可折叠布局,android,android-layout,scrollview,Android,Android Layout,Scrollview,您好,我正在使用可折叠布局,我希望布局的行为根据我的滚动事件进行更改,如图所示: 这是带有列表视图的默认图像,当用户滚动时,顶部布局应该改变,看起来像第二个图像中的布局 我应该如何使用可折叠布局实现这种行为。您只需在工具栏下添加TabLayout,如下所示 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:background="@color/colorPrimary" an
我应该如何使用可折叠布局实现这种行为。您只需在工具栏下添加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"/>
根据您的需要尝试覆盖此选项。您可以在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;
}
}
});
这对我来说很有效,试试吧……到目前为止你都试了些什么?我不想要选项卡布局。选项卡布局将保持不变,但工具栏将被替换。请参见第二张图片。我不明白你在说什么。我正在使用上面的布局进行应用程序开发