Ole*_*iov 5 android floating-action-button android-coordinatorlayout
我有一个片段活动。片段有一个协调器布局,fab是它的直接子视图和其他视图。
活动布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_layout" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
片段布局
<android.support.design.widget.CoordinatorLayout
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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.aakira.expandablelayout.ExpandableLinearLayout
android:id="@+id/statistic_expand_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
android:background="@color/colorPrimary"
android:orientation="vertical"
app:ael_duration="150"
app:ael_interpolator="accelerateDecelerate">
<com.github.mikephil.charting.charts.BarChart
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/overall_statistic_bar_chart"
android:layout_width="match_parent"
android:layout_height="@dimen/statistic_small"/>
<TextView
style="@style/SmallTextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_small"
android:gravity="center"
android:text="@string/overall_statistic"
android:textColor="@color/colorTextPrimary"/>
</com.github.aakira.expandablelayout.ExpandableLinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/statistic_expand_layout"
android:scrollbars="vertical"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_tiny"
android:layout_below="@id/statistic_expand_layout"
android:background="@drawable/shadow_updown"/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/activity_main_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_standard"
android:src="@drawable/ic_add"
app:layout_anchor="@id/recycler_view"
app:layout_anchorGravity="bottom|end"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
当我开始活动时,此片段晶圆厂位置不正确
但是当我按下任何按钮或查看fab时,它会移到右下角的正确位置。当我将此布局直接放入活动工厂时,位置总是正确的。有人可以帮我找出问题所在吗?
但是当我按下任何按钮或查看fab 时,它会转到右下角的正确位置。当我将此布局直接放入活动工厂位置时总是正确的。
解决方案:这是 的文档AppBarLayout,CoordinatorLayout其中说明了它们应该是什么样子:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!-- Your scrolling content -->
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.v7.widget.Toolbar
...
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
...
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
所以现在,RelativeLayout在你的设计中不应该存在。把the放在then的CoordinatorLayout 主布局中,使用with时Activity尽量使用因为现在想象的就是then 。AppBarLayoutToolbarCoordinatorLayoutCoordinatorLayoutRelativeLayoutAppBarLayout
就是这样。还有一件事,不要忘记将 : 添加app:layout_behavior="@string/appbar_scrolling_view_behavior"到AppBarLayout.
如果您需要任何帮助或提出问题,请告诉我。
| 归档时间: |
|
| 查看次数: |
587 次 |
| 最近记录: |