Tôi đang sử dụng một ViewPager trong một CoordinatorLayout (từ phiên bản mới nhất của Thư viện thiết kế) trong một Hoạt động. Một số phân đoạn cho ViewPager này có bố trí như RecyclerView hoặc NestedScrollView, nhưng một số không thể cuộn được cho nội dung nhỏ của chúng.Phân đoạn không cuộn trong một ViewPager bên trong CoordinatorLayout
<android.support.design.widget.AppBarLayout
android:id="@+id/tabanim_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/tabanim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabanim_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/tabanim_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Nhưng trong một Fragment với một FrameLayout như xem gốc, tôi cần phải có một nút được neo vào phía dưới, nhưng nó dường như được rút ra khỏi màn hình. Để có thể nhìn thấy nó, tôi cần phải thêm phần đệm đáy bằng với chiều cao của Thanh công cụ.
<FrameLayout 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:background="@android:color/white">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Home screen"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:gravity="center"
android:text="@string/brand"
android:textColor="@color/brandColor"
android:textSize="20sp" />
</FrameLayout>
Tương tự như vậy, bố cục_gravity được đặt thành 'center' trên phần tử dường như không ở giữa khu vực hiển thị cho đoạn này.
Hiểu biết của tôi là CoordinatorLayout chỉ có ý định làm việc với nội dung cuộn, đúng không? Vì vậy, chỉ sử dụng ViewGroup thông thường như FrameLayout, RelativeLayout, LinearLayout cho các đoạn ViewPager sẽ có phần dưới cùng của chúng được vẽ ngoài màn hình?
Trong trường hợp đó, tôi có cần xóa nút này khỏi bố cục đoạn này và di chuyển nó đến bố cục hoạt động chứa CoordinatorLayout không? Nó chỉ cần được hiển thị trên đoạn đầu tiên.
Bạn đã bao giờ nhận được một giải pháp cho việc này? – g0ld2k
@cdodo u tìm thấy giải pháp nào? – Erum
Tôi tìm thấy một giải pháp. Kiểm tra câu trả lời bên dưới – jaffa