代码之家  ›  专栏  ›  技术社区  ›  user432209

什么控制视图在UI屏幕上的显示顺序?

  •  0
  • user432209  · 技术社区  · 14 年前

    我有一个使用以下视图对象的布局应用程序。2个微调器、2个按钮、1个seekbar和一个自定义视图对象,它基本上是我绘制的画布。

    出于某种原因,旋转器和seekbar被绘制在画布的顶部,但这两个按钮不是。我不明白这是为什么。

    那么,这个命令是如何确定的呢?

    谢谢。

    根据请求编辑:xml(这是在我将customview移到顶部修复问题之前)。如果订单应该是基于XML的,那么定制视图应该已经覆盖了spinners,而不是它所覆盖的spinners。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <Spinner
            android:id="@+id/cc_component"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:drawSelectorOnTop="true"
            android:prompt="@string/cc_component_spinner" />
    
        <TextView
            android:id="@+id/desc"
            android:text="@string/step1_desc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dip"
            android:visibility="gone"
            android:layout_centerHorizontal="true"
            android:textSize="25sp"/>
    
        <Button
            android:id="@+id/switch_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"/>
    
        <com.cmllc.zcc.CCView
            android:id="@+id/cc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <Button
            android:id="@+id/switch_right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="@drawable/rightarrow1" /> 
    
        <Spinner
            android:id="@+id/component_color"
            android:layout_above="@+id/switch_color"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:drawSelectorOnTop="true"
            android:prompt="@string/component_color_spinner" />
    
        <SeekBar
            android:id="@+id/switch_color"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:max="100"
            android:minWidth="200dip"
            android:progress="50"/>
    
    </RelativeLayout>
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Community Fabien Hure    7 年前

    它应该只是添加到视图中的顺序。除了你能用的 View.bringChildToFront() .

    请看这篇文章: Defining Z order of views of RelativeLayout in Android

    在一个 post here 由谷歌的安卓开发者戴安娜·哈克伯恩(DianneHackborn)所言,她在z顺序行为方面也给出了同样的结论。

    我实现了你的布局,或者尽我所能在没有你所有资源和自定义的情况下实现 View 对象,然后我得到结果。第一个spinner、textview和button出现在自定义对象的下面,我将用以下内容来模仿它:

    <TextView
        android:id="@+id/cc"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#880000FF" />
    

    然后我看到第二个按钮,第二个旋转器,在上面看到了键盘。你的自定义视图有什么奇怪的地方吗?或者可能是由于以后对您的视图的操纵而发生的事情。

    编辑:我仔细检查了一下,我确实看到了上面描述的显示。

        2
  •  0
  •   Falmarri    14 年前

    你没有把你的任何观点与其他观点联系起来。在相对布局中,您需要告诉视图您的视图位于其他视图的上方、下方等位置。你需要给他们相对的设置,而不仅仅是在其中一些上对齐父级。