开发者

Android: RelativeLayout problem with xml

开发者 https://www.devze.com 2023-01-27 01:52 出处:网络
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.

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.

Android: RelativeLayout problem with xml

I used RelativeLayout (other layou开发者_开发技巧ts 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:

Android: RelativeLayout problem with xml

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" ]


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

Android: RelativeLayout problem with xml

-> following is triangle on left-top

Android: RelativeLayout problem with xml

-> following is diamond in left

Android: RelativeLayout problem with xml

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 !!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号