简体   繁体   English

LayerList xml 如何在 android 中中断?

[英]How does LayerList xml interrupted in android?

In the official site Layer List explanation there is an example that I can't understand.在官方网站层列表解释中有一个我看不懂的例子。

The example:这个例子:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/android_red" />
    </item>
    <item
        android:left="10dp"
        android:top="10dp">
        <bitmap
            android:gravity="center"
            android:src="@drawable/android_green" />
    </item>
    <item
        android:left="20dp"
        android:top="20dp">
        <bitmap
            android:gravity="center"
            android:src="@drawable/android_blue" />
    </item>
</layer-list>

The output: output:

输出

I can't understand two things:我无法理解两件事:

  1. Why the Red android isn't in the center.为什么红色android 不在中心。 He is the only one who doesn't have top or left offset.他是唯一没有顶部左侧偏移的人。 Maybe I don't understand the meaning of top and left offset, From which point the offset is calculated?可能我没看懂top和left offset的意思,offset是从哪一点算出来的?

  2. Does android: gravity="center" is in relation to all containers or in relation to the item above ("his sibling), ie, does the second item is in relation to the container or to the first item? android:gravity="center"是否与所有容器相关或与上述项目(“他的兄弟姐妹”)相关,即第二项与容器相关还是与第一项相关?

i think if you copy this code and try to explore it you can get the idea.我认为如果您复制此代码并尝试探索它,您就会明白这一点。 in fact the red android is in the center but it is not clear in this picture, so if you put it in imageView it will look like this实际上红色的android在中间但是这张图看不清楚,所以如果你把它放在imageView里面会是这样的

i gave background yellow color to be clear, so you can see that the red android is in the center.我给了背景黄色以清晰,所以你可以看到红色的 android 在中心。

2- android: gravity="center" is for the item that contain it, notice that the item will stretch to the parent width and height so you can notice for example that the blue android is in the center of its item which its left top corner is (10,10) and its bottom right corner is the same as the parent 2- android:gravity="center" 用于包含它的项目,请注意该项目将拉伸到父宽度和高度,因此您可以注意到例如蓝色 android 位于其左上角的项目的中心角为 (10,10) 且其右下角与父级相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM