Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置“;z指数;android上的线性布局_Android_Android Layout - Fatal编程技术网

设置“;z指数;android上的线性布局

设置“;z指数;android上的线性布局,android,android-layout,Android,Android Layout,我将在垂直线性布局上放置四个图像视图。我希望他们使用相同的空间,因此我为每个人分配了一个android:layout\u weight=“1”。我还希望它们重叠(这是一个设计要求),所以我为每个视图设置了一个负边距。我添加的最后一个图像(@+id/floor_1st)是最后一个要添加的图像(底部的图像),因此它保持在前面。然而,我希望它是另一种方式:我希望布局上的第一个图像在前面,然后是第二个,依此类推(最后一个图像应该在后面) 我知道使用RelativeLayout可以更容易地控制图像的放置顺

我将在垂直线性布局上放置四个图像视图。我希望他们使用相同的空间,因此我为每个人分配了一个
android:layout\u weight=“1”
。我还希望它们重叠(这是一个设计要求),所以我为每个视图设置了一个负边距。我添加的最后一个图像(
@+id/floor_1st
)是最后一个要添加的图像(底部的图像),因此它保持在前面。然而,我希望它是另一种方式:我希望布局上的第一个图像在前面,然后是第二个,依此类推(最后一个图像应该在后面)

我知道使用
RelativeLayout
可以更容易地控制图像的放置顺序,但我不知道如何使用此布局以我想要的方式放置图像。我还看到,可以使用方法
bringToFront()
,但这只是不允许图像重叠

那么,有没有办法使用
LinearLayout
按我想要的顺序放置图像?或者我应该使用另一种布局?在这种情况下,我应该如何放置图像

这是我的xml代码

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/floors_container"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="@dimen/overview_buttons_top_margin"
    android:layout_marginBottom="@dimen/overview_buttons_bottom_margin"
    >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/floor_4th"
        android:src="@drawable/piso_4"
        android:layout_weight="1"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="@dimen/floors_overview_margin_three_quarter"
        android:clickable="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/floor_3rd"
        android:src="@drawable/piso_3"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1"
        android:layout_marginTop="@dimen/floors_overview_margin_quarter"
        android:layout_marginBottom="@dimen/floors_overview_margin_half"
        android:clickable="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/floor_2nd"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/piso_2"
        android:layout_weight="1"
        android:layout_marginTop="@dimen/floors_overview_margin_half"
        android:layout_marginBottom="@dimen/floors_overview_margin_quarter"
        android:clickable="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/floor_1st"
        android:src="@drawable/piso_1"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1"
        android:layout_marginTop="@dimen/floors_overview_margin_three_quarter"
        android:clickable="true" />
</LinearLayout>


谢谢。

对于21级的Android,您可以使用view.setZ()


对于低于21级的Android,我建议使用FrameLayout或RelativeLayout,并结合使用bringToFront()和/或负填充,如果需要,使用边距。关于bringToFront()方法的使用,请参阅此

,以实现这种布局框架布局将是您的最佳选择

此布局通常用于基于z索引的结构(重叠)。看看这门课吧:-

以下是一个显示其用途的链接:-

你也可以找到其他链接来演示它的使用

希望有帮助


谢谢。

如果要反转绘图顺序,需要对LinearLayout类进行子类化并重写getChildDrawingOrder

@Override
protected int getChildDrawingOrder(int childCount, int i) {
    //The standard implementation just retuns i
    return childCount - i - 1;
}
请确保在以下位置启用自定义订购:

setChildrenDrawingOrderEnabled(true);

为每个
ImageView
提供一个水平方向的
LinearLayout
,然后我如何控制“z索引”?对于z索引,您可以从顶部以负片形式设置边距,如
marginTop=“-20dp”
,这就是我目前正在做的。我定义的上/下页边距为负值。