Android: xml的RelativeLayout问题

发布于 2024-10-04 18:19:12 字数 1506 浏览 0 评论 0原文

我正在尝试放置一些三角形和以某种方式在Android屏幕上显示方块,如下图所示。我将它们分开放置,因为所有形状都是可点击的。

alt text

我使用了RelativeLayout(我尝试过其他布局,但它们不起作用)。以下是相同的 xml 代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
    android:id="@+id/LeftTopTriangle"
    android:src="@drawable/a_triangle_towards_right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="true"
    android:layout_alignTop="true"
    android:clickable="true" />
<ImageView
    android:id="@+id/TopLeftTriangle"
    android:src="@drawable/a_triangle_towards_bottom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="true"
    android:layout_alignTop="true"
    android:clickable="true" />
<ImageView
    android:id="@+id/LeftBottomTriangle"
    android:src="@drawable/a_triangle_towards_right"
    android:layout_below="@id/LeftTopTriangle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true" />

这里我只尝试 3 个三角形,2 个在左上角,1 个在左下角。现在无论如何,我试错了,不知怎的,底部的三角形永远不会出现。 我最终如下: 替代文本 任何人都有想法,如何实现它? [PS:奇怪的是,在 xml 文件中,即使从 ImageView 中删除以下行,我也得到相同的数字 机器人:layout_alignLeft =“真” 机器人:layout_alignTop =“真” ]

I am trying to put some triangles & squares on Android screen in certain way as shown in following figure. I am putting them separately because all shapes are clickable.

alt text

I used RelativeLayout (other layouts I tried, but they aren't working). Following is xml code for the same:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
    android:id="@+id/LeftTopTriangle"
    android:src="@drawable/a_triangle_towards_right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="true"
    android:layout_alignTop="true"
    android:clickable="true" />
<ImageView
    android:id="@+id/TopLeftTriangle"
    android:src="@drawable/a_triangle_towards_bottom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="true"
    android:layout_alignTop="true"
    android:clickable="true" />
<ImageView
    android:id="@+id/LeftBottomTriangle"
    android:src="@drawable/a_triangle_towards_right"
    android:layout_below="@id/LeftTopTriangle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true" />

Here I am trying only 3 triangles, 2 on the left-top corner and one on the left-bottom corner. Now whatever, I trial-error, somehow the bottom triangle never shows up.
I end up as following:
alt text
Any one have idea, how to achieve it ?
[P.S.: Strangely in the xml file, I am getting the same figure even removing following lines from both the ImageViews
android:layout_alignLeft="true"
android:layout_alignTop="true"
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅笑依然 2024-10-11 18:19:12

我找到了一种更简单的方法来实现这一目标。
我已经以相同的尺寸宽度x高度分别绘制了所有图像。
例如,如果整体图像尺寸为 400 x 300,那么我将在同一 400 x 300 帧中的给定点处单独绘制所有三角形和菱形。

-> 以下是左上角的三角形
替代文本

->以下是左上角的三角形
替代文本

->以下是左边的菱形
alt text

另请注意,每个人的背景都已被删除(通过 PAINT.net),以便它们可以相互重叠(否则最终图像将仅可见)。
现在,所有图像都将在 FrameLayout 中简单地声明为scaleType =“fitXY”。
完毕 !!

I have found one easier way to achieve this.
I have drawn all the images separately in the same dimension width x height.
e.g. If the overall image size is 400 x 300 then, I would draw all the triangles and diamonds individually at given points in the same 400 x 300 frame.

->following is triangle on top-left
alt text

-> following is triangle on left-top
alt text

-> following is diamond in left
alt text

Also note that, everyone's background has been removed (by PAINT.net) so that they can overlap on each other (otherwise final image will be only visible).
Now all images will be simply declared in FrameLayout with scaleType="fitXY".
Done !!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文