簡體   English   中英

Android XML設置z-Index

[英]Android XML setting z-Index

基本上我有2個線性布局。 當用戶單擊按鈕時,一種線性布局將展開或折疊。 另一個將始終顯示在頂部。 這是我的xml:

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

<Button
            android:id="@+id/btnNewsFeed"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/lightred"
            android:minHeight="20dp"
            android:text="News feed"
            android:textColor="#FFFFFF" />
<LinearLayout
            android:id="@+id/llNewsFeed"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/btnNewsFeed"
            android:background="#FFFFFF"
            android:orientation="vertical"
            android:visibility="gone" >

            <ListView
                android:id="@+id/EventNewsFeedListview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:listSelector="#F6CECE" >
            </ListView>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/legendDiv"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_below="@+id/btnNewsFeed"
            android:alpha=".75"
            android:background="#fff"
            android:orientation="vertical"
            android:visibility="gone" >

            <TableLayout
                android:id="@+id/tableEvent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:stretchColumns="1"
                android:visibility="gone" >
                //Table Rows
            </TableLayout>
        </LinearLayout>


</RelativeLayout>

因此,當用戶在導航抽屜項上選擇時,我的圖例div將顯示,並且其不透明度為0.75。 當btnNewsFeed onClick時,我的llNewsfeed將被展開或折疊。 現在我遇到的問題是,當顯示legendDiv時,llNewsFeed隱藏在legendDiv后面。 我想知道是否有任何可能的方法來設置z-index? 因為llNewsFeed應該位於legendDiv的前面。

有指導嗎? 提前致謝。

您可以使用諸如以下的BringToFront方法

myView.bringToFront(); 

另請閱讀此內容-定義視圖的Z順序。 它可能會有所幫助。

從API級別21開始,您可以使用View.setZ(float)View.setTranslationZ(float)設置z-index

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM