如何在xml中的另一个组件后面隐藏布局?

时间:2019-07-31 05:10:46

标签: android kotlin

我想在activity_main.xml中的另一个组件后面隐藏一个布局。我使用的是底页纸,只想查看顶部。底部应隐藏在我的工具栏后面。是否存在将布局推到组件后面的函数或属性?

main_activity.xml

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <fragment
        android:id="@+id/top_app_bar"
        android:name="com.ds.base.fragments.TopAppBarFragment"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_constraintBottom_toTopOf="@+id/include"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="spread" />

    <include
        android:id="@+id/include"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        layout="@layout/content_main"
        app:layout_constraintBottom_toTopOf="@+id/main_bottom_app_bar"
        app:layout_constraintStart_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/top_app_bar"/>

    <fragment
        android:id="@+id/main_bottom_app_bar"
        android:name="com.ds.base.fragments.BottomAppBarFragment"
        android:layout_width="match_parent"
        android:layout_height="90dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/include">

    </fragment>


    <include
        android:id="@+id/time_remaining_layout"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        layout="@layout/time_remaining_bottom_sheet"
        app:layout_constraintTop_toTopOf="@id/main_bottom_app_bar"/>

</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

2 个答案:

答案 0 :(得分:0)

在xml中使用

android:visibility="gone"

android:visibility="invisible"

还用于Java(活动)代码

view.setVisibility(View.INVISIBLE);

view.setVisibility(View.GONE);

答案 1 :(得分:0)

要将任何View带到顶部,您必须致电 yourView.bringToFront()