我有一个片段活动。片段有一个协调器布局,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>
片段布局
<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>
当我开始活动与此片段晶圆厂位置不正确
但是当我按任何按钮或视图晶圆厂在r的正确位置ight底角。当我把这个布局直接放到活动晶圆厂的位置上时,总是正确的。有谁能帮我弄清楚有什么问题吗?
你好,谢谢你的回答,但是我在问题描述中做了一个错误。当我**将fragment的布局直接放入fragment_container位置的activity **时,一切都很好,但是当**我将fragment的布局用作activity布局**时。我需要这个RelativeLayout来将RecyclerView放置在Expandable布局下。 –
为什么不能在** Activity Layout **中使用'CoordinatorLayout'然后将FloatingActionButton放在正确的位置?我只是在想,为什么你把'Toolbar'放在'LinearLayout'里面,然后把'CoordinatorLayout'放在没有'Toolbar'和'AppBarLayout'的片段上!我不认为如果这种布局设计是正确的! – Mohsen
你是对的,我用协调器布局重写了我的活动布局,现在一切都很好。谢谢:) –