코디네이터 레이아웃의 도구 모음 아래에 보기 추가
저는 다음과 같은 레이아웃을 가지고 있습니다.
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/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.AppBarLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.design.widget.CoordinatorLayout>
덧붙입니다Fragment
속으로FrameLayout
, 그들을 대신할 겁니다.나의 하나Fragment
는 목록이며, 레이아웃은 다음과 같습니다.
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
여기서 문제는 도구 모음이 목록 위에 그려져 있다는 것입니다.저는 그 내용을 포장해서 해결하려고 했습니다.CoordinatorLayout
로LinearLayout
, 오버드로우는 해결했지만 앱바 스크롤 동작은 더 이상 작동하지 않습니다.
어떤 도움이라도 주시면 감사하겠습니다!
속성을 가져옵니다.
app:layout_behavior="@string/appbar_scrolling_view_behavior"
외지에서RecyclerView
그 위에 올려놓습니다.FrameLayout
당신이 보여주려는 것은Toolbar
.
스크롤 뷰 동작이 수행하는 한 가지 중요한 것은 도구 모음 아래에 구성 요소를 배치하는 것입니다.왜냐하면.FrameLayout
스크롤할 하위 항목이 있습니다(RecyclerView
), .CoordinatorLayout
이동을 위해 스크롤 이벤트를 받을 것입니다.Toolbar
.
그 밖에 주의해야 할 사항은 다음과 같습니다.그 레이아웃 동작은 다음과 같은 결과를 초래할 것입니다.FrameLayout
높이는 이미 스크롤 된 것처럼 크기가 지정됩니다.Toolbar
전체 보기가 완전히 표시됨으로써 보기의 아래가 아래로 내려가기만 합니다.CoordinatorLayout
.
이것은 저에게 놀라운 일이었습니다.툴바가 위아래로 스크롤되면서 뷰가 동적으로 크기가 조정될 것으로 예상했습니다.따라서 보기 하단에 고정 구성요소가 있는 스크롤 구성요소가 있는 경우 해당 하단 구성요소를 완전히 스크롤하기 전에는 볼 수 없습니다.Toolbar
.
그래서 UI 하단에 버튼을 고정하고 싶을 때는 하단에 버튼을 넣어서 이 부분을 해결했습니다.CoordinatorLayout
(android:layout_gravity="bottom"
도구 모음 아래의 보기에 단추 높이와 동일한 하단 여백을 추가합니다.
다음을 추가하여 이 문제를 해결할 수 있었습니다.
Android:layout_marginTop="?android:tractor/actionBarSize"
다음과 같이 프레임 레이아웃에 적용할 수 있습니다.
<FrameLayout
android:id="@+id/content"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
상단 도구 모음을 접거나 원하는 대로 ScrollFlags를 사용하려면 다음과 같은 방법을 사용할 수 있습니다.소재 디자인부터 프레임 배치 제거
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="top"
app:layout_scrollFlags="scroll|enterAlways">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
<ImageView
android:id="@+id/ic_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_back" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="back"
android:textSize="16sp"
android:textStyle="bold" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/post_details_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Android studio 3.4의 경우, 당신은 이 줄을 당신의 레이아웃에 넣어야 합니다.RecyclerView
.
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
언급URL : https://stackoverflow.com/questions/32956071/add-views-below-toolbar-in-coordinatorlayout
'programing' 카테고리의 다른 글
TensorFlow에서 tf.app.flags의 목적은 무엇입니까? (0) | 2023.10.31 |
---|---|
Android ndk/jni와 함께 C++ 사용 (0) | 2023.10.31 |
LocalStorage에서 부울 값을 설정할 수 없습니까? (0) | 2023.10.31 |
ID에 대괄호가 포함된 경우 ID로 DOM 요소를 찾으십니까? (0) | 2023.10.26 |
응용프로그램별 링커 스크립트에 정의된 접근 기호 (0) | 2023.10.26 |