三个图像,当他们按顺序放置时看起来像android中的三角形

时间:2014-08-07 11:17:48

标签: android android-layout

enter image description here

我有三个不同的图像,橙色,绿色和蓝色。我必须将它们对齐以在android中创建一个三角形。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/header"
        android:layout_centerHorizontal="true" >

        <FrameLayout
            android:id="@+id/fl1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" >

            <ImageView
                android:id="@+id/bg1"
                android:layout_width="160dp"
                android:layout_height="160dp"
                android:layout_centerInParent="true"
                android:layout_marginLeft="10dp"
                android:adjustViewBounds="true"
                android:background="@drawable/a1_home" />
        </FrameLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/fl1"
            android:orientation="horizontal" >

            <FrameLayout
                android:id="@+id/fl2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <ImageView
                    android:id="@+id/bg2"
                    android:layout_width="160dp"
                    android:layout_height="160dp"
                    android:layout_above="@+id/footer"
                    android:layout_below="@+id/bg1"
                    android:adjustViewBounds="true"
                    android:background="@drawable/a2_home" />
            </FrameLayout>

            <FrameLayout
                android:id="@+id/fl3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <ImageView
                    android:id="@+id/bg3"
                    android:layout_width="160dp"
                    android:layout_height="160dp"
                    android:adjustViewBounds="true"
                    android:background="@drawable/a3_home" />
            </FrameLayout>
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

然后我们之间有空格。输出是这样的...... enter image description here

我想减少三幅图像之间的空间..我需要像第一张图像一样制作图像。请帮忙

2 个答案:

答案 0 :(得分:1)

您有两种选择:

  1. 尝试在内侧给出FrameLayouts 负边距(即顶视图的marginBottom,左视图的marginTop和marginRight,右视图的marginTop和marginRight)。负利润将把观点推到一起。继续调整这些数字并进行测试,直到您满意为止。

  2. 您也可以创建一个包含所有三个部分的单个图像,然后在ImageView顶部放置三个invsibile视图,基本上在每个部分的顶部放置一个(我假设您需要这些部分来制作可点击区域)。 / p>

答案 1 :(得分:0)

您必须自定义视图:

 public class CustomView extends View{

  public CustomView(Context context){
   super(context);
  }  

@Override
private onDraw(Canvas canvas){
  super.onDraw(canvas)
 // now you get canvas to draw whatever you want
 //canvas.drawBitmap() draw a bitmap and place it

 }

}
相关问题