[英]layout behavior not working in frame layout
我正在嘗試使內容滾動時隱藏/顯示我的工具欄,當我將其注入FrameLayout容器並且它不起作用時,這是我的appbar布局:
<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,但它沒有隱藏。
布局inflater的問題我改變了我的布局inflater:
FrameLayout container = (FrameLayout) findViewById(R.id.content_frame);
View inflatedLayout= getLayoutInflater().inflate(R.layout.activity_user, null, false);
container.addView(inflatedLayout);
請使用android.support.design.widget.CollapsingToolbarLayout
在滾動期間環繞要隱藏/顯示的項目
在這里閱讀有關主題的更多信息, 折疊工具欄布局
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.