繁体   English   中英

如何在LinearLayout中添加不可见视图?

[英]How to add an invisible view into LinearLayout?

是否可以在LinearLayout中添加不可见的视图/视图组,而这不会影响布局的其他子级的大小。 这是详细信息。

我有一个简单的LinearLayout,底部有一个工具栏,RecyclerView和一个TextView。

<?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>

现在,我想添加一个实际上可见但不影响其他小部件的大小和位置的视图或视图组,并使用.offsetTopAndBottom方法将其隐藏。
之后,使用ViewDragHelper类基于某些手势显示视图。 实际上,该行为类似于BottomSheetBehavior,但不涉及CoordinatorLayout。
唯一的问题是我无法弄清楚如何将视图添加到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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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