我有一個片段活動。片段有一個協調器佈局,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
你是對的,我用協調器佈局重寫了我的活動佈局,現在一切都很好。謝謝:) –