【问题标题】:Z-index in android?android中的Z索引?
【发布时间】:2012-12-27 07:42:02
【问题描述】:

我在一个 xml 中有多个元素.. 列表视图、滑动抽屉、编辑文本和按钮... 我想滑动抽屉顺序总是在另一个元素的前面...但我不能..

这里是我的xml

<com.ltvie.chat.MultiDirectionSlidingDrawer
    xmlns:my="http://schemas.android.com/apk/res/com.ltvie.chat"
    android:id="@+id/drawer"
    my:direction="topToBottom"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    my:handle="@+id/handle"
    my:content="@+id/content"
    >
   <include
        android:id="@id/content"
        layout="@layout/pen_content"
        android:gravity="top"           
        />
     <ImageView
        android:id="@id/handle"
        android:layout_width="wrap_content"
        android:layout_height="5dp"
        android:src="@drawable/sliding_drawer_handle_bottom" />          
</com.ltvie.chat.MultiDirectionSlidingDrawer>

<ListView android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stackFromBottom="true"
    android:transcriptMode="alwaysScroll"
    android:layout_above="@+id/InnerRelativeLayout"
    android:layout_alignParentTop="true" 
/>  
 <RelativeLayout 
    android:id="@+id/InnerRelativeLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >
    <Button 
        android:text="kirim" 
        android:id="@+id/button_send"
        android:layout_alignParentRight="true" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="tambahItems"          
        >
        
    </Button>           
</RelativeLayout>

mycode 的结果如下图所示:D

我想知道如何解决它??

注意,

【问题讨论】:

    标签: android xml listview layout slidingdrawer


    【解决方案1】:

    您的 xml 不包含您的外部布局,但我认为它是一个相对布局。在RelativeLayout 中,元素的 z 级别由它们添加到容器中的顺序决定。稍后添加的视图将位于顶部。尝试将滑动抽屉移动到外部容器的底部。像这样——

    <ListView android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll"
        android:layout_above="@+id/InnerRelativeLayout"
        android:layout_alignParentTop="true" 
    />  
     <RelativeLayout 
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >
        <Button 
            android:text="kirim" 
            android:id="@+id/button_send"
            android:layout_alignParentRight="true" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="tambahItems"          
            >
    
        </Button>           
    </RelativeLayout> 
    
    <com.ltvie.chat.MultiDirectionSlidingDrawer
        xmlns:my="http://schemas.android.com/apk/res/com.ltvie.chat"
        android:id="@+id/drawer"
        my:direction="topToBottom"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        my:handle="@+id/handle"
        my:content="@+id/content"
        >
       <include
            android:id="@id/content"
            layout="@layout/pen_content"
            android:gravity="top"           
            />
         <ImageView
            android:id="@id/handle"
            android:layout_width="wrap_content"
            android:layout_height="5dp"
            android:src="@drawable/sliding_drawer_handle_bottom" />          
    </com.ltvie.chat.MultiDirectionSlidingDrawer>
    

    【讨论】:

    • 正确,您显示的外部布局是相对布局。将整个滑动抽屉块移动到您显示的 xml 代码的底部。 (见编辑)。
    • slidingdrawer 成功在前面..但我遇到了新问题...listview 不显示,,,我收到错误 java.lang.ClassCastException: android.widget.listview
    • xml 更改不应导致该错误。你最近改变了你的java代码吗?我需要查看更多的 logcat 和代码来告诉你那里发生了什么。
    【解决方案2】:

    您可以根据需要为 Z 添加翻译 (1dp,2pd,...) 喜欢:

    <ImageView
        android:id="@+id/imageView0"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:layout_marginTop="25dp"
        android:contentDescription="@string/desc"
        android:translationZ="1dp"
        app:srcCompat="@drawable/ic_icon" />
    

    【讨论】:

      【解决方案3】:

      如果不是相对布局,可以使用 [your_variable].bringToFront()。

      这对我有用! (而且我正在使用约束布局)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-22
        • 2012-06-03
        • 1970-01-01
        • 2013-06-02
        • 1970-01-01
        • 1970-01-01
        • 2019-04-06
        相关资源
        最近更新 更多