我有一个AppBarLayout
(高度设置为wrap_content
),里面有一个Toolbar
和一个工具栏形状的按钮(由CoordinatorLayout
制造)。单击按钮后,我要使其为gone
并进行其他显示(RecyclerView
)visible
,该视图将占据整个屏幕({ {1}},它是match_parent
的父级。当我将CoordinatorLayout
设为AppBarLayout
时,视图不会占据整个屏幕,只是占据了整个屏幕的一半。
对于其父级设置为visible
的视图,是否有“匹配父级的父级”尺寸常量?
在单击按钮之前: Before clicking the button
单击按钮后: After clicking the button
代码:
match_parent
PS::有人请更改图像的链接,我没有足够的声誉。
PS 2:我知道一种实现此目的的方法是以编程方式将wrap_content
的高度设置为<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PedidosActivity">
<!-- Screen content below toolbar -->
.
.
.
<!-- End of screen content -->
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbarPedidos"
android:background="@color/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways|snap" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/btnLineaLayout"
android:visibility="gone"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:background="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/btnLinea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/linea"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:src="@drawable/baseline_keyboard_arrow_down_24"
android:tint="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@id/textView2"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:background="@color/colorPrimary"
android:visibility="visible" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
,但似乎“肮脏”而不优雅。
答案 0 :(得分:0)
我在您的代码中找不到RelativeLayout
。但是当您这样做时,RelativeLayout
应该会覆盖整个屏幕
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PedidosActivity">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
</RelativeLayout>
.
.
.