簡體   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