【发布时间】:2019-05-19 11:14:52
【问题描述】:
我试图让我的工具栏在内容滚动时隐藏/显示,当我将它注入 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,但它没有隐藏。
【问题讨论】:
-
去这个链接stackoverflow.com/questions/35475884/…,希望对你有帮助
-
其他解决方案是将工具栏布局也放入嵌套的scoolview中......如果你也想滚动工具栏
-
我将工具栏布局放在嵌套滚动视图中,但应用程序崩溃了。
-
请给我看你的代码..同时显示你遇到的崩溃日志