简体   繁体   中英

How to add an invisible view into LinearLayout?

Is that possible to add an invisible view/view group into LinearLayout which will not affect sizes of other children of the layout. Here are details.

I have a simple LinearLayout with a Toolbar, RecyclerView and a TextView at the bottom.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="?android:attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent" android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/list_background" />

    <TextView
        android:layout_width="match_parent" android:layout_height="48dp"
        android:text="@string/empty"/>

</LinearLayout>

Now I want to add a view or view group which is actually visible but not affect sizes and locations of other widgets and hide it with .offsetTopAndBottom method.
After that to use ViewDragHelper class to show the view based on some gestures. Actually the behavior is similar to BottomSheetBehavior but without CoordinatorLayout involved.
The only problem is that I cannot figure out how to add the view into LinearLayout.

为了使景观不仅看不见,而且不占用任何空间,因此没有无论是在XML使用android_visibility =“水涨船高”,或在使用yourView.setVisibility代码布局的行为,如WRAP_CONTENT或layout_weight您可以在视图可见性设置为干扰(View.GONE)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:background="?android:attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent" android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@color/list_background" />

<TextView
    android:layout_width="match_parent" android:layout_height="48dp"
    android:text="@string/empty"/>
     <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:layout_marginTop="10dp"
        android:textColorHint="@android:color/white"
        android:textColor="@android:color/white"
        android:hint="@string/loginEmailHint"
        android:id="@+id/loginEmail"
        android:visibility="gone"/>

</LinearLayout>


Here a an example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM