android.support.v7.widget.Toolbar 将内容推到底部
android.support.v7.widget.Toolbar pushes content to the bottom
android.support.v7.widget.Toolbar
好像把内容推到了底部,看看这些截图:
这个画面是切换到片段时的原始状态:
向下滚动一点后我可以看到完整的布局:
那么如何防止滚动呢?如果我从 xml 代码中删除 android.support.v7.widget.Toolbar
,一切都会按预期工作(除了缺少工具栏,哈哈)。
这是主要代码 activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
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="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_add"/>
</android.support.design.widget.CoordinatorLayout>
下面是聊天片段的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="@null"
android:stackFromBottom="true"
android:transcriptMode="normal" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="2dp" >
<EditText
android:id="@+id/enter_message"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.85"
android:hint="hint"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="5" />
<Button
android:id="@+id/send_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:background="@drawable/common_google_signin_btn_icon_dark_normal" />
</LinearLayout>
</LinearLayout>
按照其他线程中的建议删除 android:fitsSystemWindows="true"
,但没有任何改变。提前致谢!
在主 activity 布局中将 CoordinatorLayout 替换为 RelativeLayout。
此外,将其添加到您的 RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
旁注:删除 CoordinatorLayout 会影响您的 FloatingActionButton 行为。您可以删除 FloatingActionButton 并将其放在聊天片段中。如果要这样做,请确保将 LinearLayout 替换为 CoordinatorLayout
我不确定我得到了你想要的行为。您可能希望保持布局不变,但只需从工具栏中删除滚动标志:
app:layout_scrollFlags="scroll|enterAlways"
这些标志告诉工具栏听取回收器视图上的滚动并做出相应的反应。据我了解,您希望工具栏保持固定。因此,删除该行。
android.support.v7.widget.Toolbar
好像把内容推到了底部,看看这些截图:
这个画面是切换到片段时的原始状态:
向下滚动一点后我可以看到完整的布局:
那么如何防止滚动呢?如果我从 xml 代码中删除 android.support.v7.widget.Toolbar
,一切都会按预期工作(除了缺少工具栏,哈哈)。
这是主要代码 activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
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="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_add"/>
</android.support.design.widget.CoordinatorLayout>
下面是聊天片段的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="@null"
android:stackFromBottom="true"
android:transcriptMode="normal" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="2dp" >
<EditText
android:id="@+id/enter_message"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.85"
android:hint="hint"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="5" />
<Button
android:id="@+id/send_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:background="@drawable/common_google_signin_btn_icon_dark_normal" />
</LinearLayout>
</LinearLayout>
按照其他线程中的建议删除 android:fitsSystemWindows="true"
,但没有任何改变。提前致谢!
在主 activity 布局中将 CoordinatorLayout 替换为 RelativeLayout。
此外,将其添加到您的 RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
旁注:删除 CoordinatorLayout 会影响您的 FloatingActionButton 行为。您可以删除 FloatingActionButton 并将其放在聊天片段中。如果要这样做,请确保将 LinearLayout 替换为 CoordinatorLayout
我不确定我得到了你想要的行为。您可能希望保持布局不变,但只需从工具栏中删除滚动标志:
app:layout_scrollFlags="scroll|enterAlways"
这些标志告诉工具栏听取回收器视图上的滚动并做出相应的反应。据我了解,您希望工具栏保持固定。因此,删除该行。