我正在尝试在滚动内容时隐藏/显示我的工具栏,当我将其注入到FrameLayout容器中并且不起作用时,这是我的应用栏布局:
<android.support.design.widget.CoordinatorLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BaseActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/tool_bar_bg"
app:elevation="0dp"
android:theme="@style/AppTheme.AppBarOverlay"
android:fitsSystemWindows="true"
android:id="@+id/app_bar_layout">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_scrollFlags="scroll|enterAlways"
android:background="@drawable/bg_actionbar"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<!-- My scrolling content -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
和我的SecondActivity布局
<android.support.v4.widget.NestedScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="true"
android:gravity="center"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<TextView
android:id="@+id/textone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/content"
android:textSize="25dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
这是我的Java代码,它可以简化活动布局:
public class FirstActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//inflate your activity layout here!
@SuppressLint("InflateParams")
View contentView = inflater.inflate(R.layout.activity_user, null, false);
drawer.addView(contentView, 0);
}
当我滚动它不起作用时,我也用RelativeLayout,LinearLayout
签入SecondActivity,但是它没有隐藏。
答案 0 :(得分:0)
布局充气机的问题我已经更改了布局充气机:
FrameLayout container = (FrameLayout) findViewById(R.id.content_frame);
View inflatedLayout= getLayoutInflater().inflate(R.layout.activity_user, null, false);
container.addView(inflatedLayout);
答案 1 :(得分:0)
请使用android.support.design.widget.CollapsingToolbarLayout
在此处详细了解该主题, collapsing-toolbar-layout