Tôi gặp sự cố khi sử dụng Thư viện hỗ trợ thiết kế Android. Tôi muốn sử dụng CoordinatorLayout bên trong đoạn cho FAB và ActionBar hình ảnh động trong khi di chuyển, nhưng tôi có ActionBar trong bố trí hoạt động và CardGridStaggeredView của tôi và FAB trong đoạn.Sử dụng CoordinatorLayout trong các đoạn với ActionBar trong Hoạt động
hoạt động bố trí:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:app1="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout <!--Here I display fragments-->
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:menu="@menu/drawer"
app1:itemTextColor="@android:color/black"/>
</android.support.v4.widget.DrawerLayout>
đoạn bố trí:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/FragmentTheme"
tools:context="androidhive.info.materialdesign.activity.HomeFragment">
<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<it.gmariotti.cardslib.library.extra.staggeredgrid.view.CardGridStaggeredView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:padding="1dp"
android:gravity="center"
card:list_card_layout_resourceID="@layout/carddemo_extras_base_staggered_card"
style="@style/main_layout_foreground"
android:id="@+id/cgvImages"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add"
android:layout_gravity="bottom|end"
app:elevation="6dp"
app:pressedTranslationZ="12dp"/>
</FrameLayout>
</RelativeLayout>
Tôi cố gắng để sử dụng CoordinatorLayout trong hoạt động và Fragment, nhưng nó đã không làm việc. Có cách nào để sử dụng CoordinatorLayout với ActionBar trong Hoạt động và các chế độ xem khác trong phân đoạn không?
Cảm ơn bạn đã trả lời. Bây giờ nó hoạt động, nhưng CardGridStaggeredView của tôi không hiển thị trong NestedScrollView. Nếu tôi xóa Thẻ NestedScrollView thì hiển thị, nhưng sau đó hoạt ảnh không hoạt động. –
Đúng vậy ... không phải tất cả các kết hợp đều hoạt động với các điều khiển hiện tại. Cố gắng đưa các điều khiển của bạn bên trong android.support.v7.widget.CardView Vì vậy, hệ thống cấp bậc đó là NestedScrollView> –
Tôi đang đấu tranh với điều này là tốt. Tôi đang cố gắng để có được bối cảnh được vẽ phía sau thanh trạng thái, nhưng nó vẫn được vẽ bên dưới bằng cách sử dụng mã của bạn. Còn thiếu gì nữa không? Tôi có các cờ 'fitsSystemWindows' được đặt chính xác như bạn có. Có bất kỳ mã nào cần phải đi trong các mảnh? – Pin