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

Android:xml的相对延迟问题

  •  1
  • iammilind  · 技术社区  · 15 年前

    我试着在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个。不管怎样,我试错了,不知怎么的,底部的三角形从来没有出现过。 我的结论如下: alt text 有人知道,如何实现它吗? [P.S.:奇怪的是,在xml文件中,我得到了相同的图形,甚至从两个ImageView中删除了以下行 android:layout_alignLeft=“真” android:layout_alignTop=“真” ]

    1 回复  |  直到 15 年前
        1
  •  0
  •   iammilind    15 年前

    我找到了一个更容易实现的方法。 我已经在同一尺寸,宽度x高度分别绘制了所有的图像。 例如,如果总图像大小为400 x 300,我将在同一个400 x 300帧中的给定点分别绘制所有三角形和菱形。

    ->下面是左上角的三角形 alt text

    ->下面是左上角的三角形 alt text

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

    还要注意的是,每个人的背景都被删除了(通过PAINT.net),这样他们可以相互重叠(否则最终的图像将只可见)。 现在,所有图像都将在FrameLayout中用scaleType=“fitXY”简单地声明。 完成!!