如何在Android中设计框架?

如何在Android中设计框架?,android,android-layout,Android,Android Layout,我想为该框架的顶部、底部、左侧和右侧分别使用4ImageView设计一个框架,如下例所示: 看起来很简单,但我真的很难做到。我尝试使用FrameLayout以及layout|left | Right | Top | Bottom,如下所示: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

我想为该框架的顶部、底部、左侧和右侧分别使用4
ImageView
设计一个框架,如下例所示:

看起来很简单,但我真的很难做到。我尝试使用
FrameLayout
以及
layout|left | Right | Top | Bottom
,如下所示:

<?xml version="1.0" encoding="utf-8"?>
 <FrameLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/camera_masque"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="#FFFFFF"
     >
        <ImageView
            android:id="@+id/camera_top_masque"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_top_masque_photo"
            android:layout_alignParentTop="true"
        />

        <ImageView
            android:id="@+id/camera_left_masque"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_left_masque_photo"
            android:layout_alignParentLeft="true"
        />

        <ImageView
            android:id="@+id/camera_right_masque"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_right_masque_photo"
            android:layout_alignParentRight="true"
        />

         <ImageView
            android:id="@+id/camera_bottom_masque"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_bottom_masque_photo"
            android:layout_alignParentBottom="true"
        />
</FrameLayout> 
但同样的事情,并没有达到预期的效果

知道我的布局有什么问题吗?我怎样才能做到这一点

注:图像大小为:640*114px(顶部、底部)和34*572(左侧、右侧)


谢谢

我通常使用linearlayout处理类似的问题,并使用布局权重参数控制填充。你可能会在这里发现很多类似的问题

简单地创建垂直线性布局,在中间部分创建水平线性布局。

如果在EclipseADT中使用WYSIWYG布局设计器,这将变得简单得多。有关详细信息,请参阅


Android版面有很多教程,这是一个更有用的资源,因为堆栈溢出倾向于处理编程问题,而不是版面。

我通常使用linearlayout来处理这类问题,并使用版面权重参数控制填充。你可能会在这里发现很多类似的问题

简单地创建垂直线性布局,在中间部分创建水平线性布局。

如果在EclipseADT中使用WYSIWYG布局设计器,这将变得简单得多。有关详细信息,请参阅


Android版面有很多教程,这是一个更有用的资源,因为堆栈溢出倾向于处理编程问题而不是版面问题。

我将回答我自己的问题,以突出我所犯的错误。结果是,我几乎就到了,我只需要在右边和左边的
ImageView
s添加一个
alignParentTop
,在底部的
ImageView
添加一个
alignParentLeft


不过,我不明白这背后的逻辑!(如果有人能解释…

我会回答我自己的问题,以突出我所犯的错误。结果是,我几乎就到了,我只需要在右边和左边的
ImageView
s添加一个
alignParentTop
,在底部的
ImageView
添加一个
alignParentLeft


不过,我不明白这背后的逻辑!(如果有人可以解释…

如果框架是由相同的图像构建的。如果框架是由相同的图像构建的,您可以尝试一个或一个带有边框和透明中心的形状。

。您可以尝试一个或一个带有边框和透明中心的形状。

我将坚持使用
相对布局
,因为它比使用2
线性布局更有效。您关于在ADT中使用所见即所得工具的建议很好。它帮助我找到了我的错误:结果我不得不在右边和左边
ImageView
s添加一个
alignParentTop
,在底部
ImageView
添加一个
alignParentLeft
。我不明白这背后的逻辑…如果你是指它可能在这种情况下是可以接受的,但你可以混合和匹配使用一个亲戚作为一个线性的中间行。有时候,知道一个布局将如何运行比效率更重要,尽管在设计更复杂的布局和列出我在那篇文章中提到的项目时应该小心。同意第二点!我将坚持使用
相对布局
,因为它比使用2
线性布局
更有效。您关于在ADT中使用所见即所得工具的建议很好。它帮助我找到了我的错误:结果我不得不在右边和左边
ImageView
s添加一个
alignParentTop
,在底部
ImageView
添加一个
alignParentLeft
。我不明白这背后的逻辑…如果你是指它可能在这种情况下是可以接受的,但你可以混合和匹配使用一个亲戚作为一个线性的中间行。有时候,知道一个布局将如何运行比效率更重要,尽管在设计更复杂的布局和列出我在那篇文章中提到的项目时应该小心。同意第二点!实际上有两个图像。除此之外,好主意。实际上有两张图片。除此之外,好主意。
<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/camera_masque"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="#FFFFFF"
     >
        <ImageView
            android:id="@+id/camera_top_masque"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_top_masque_photo"
            android:layout_alignParentTop="true"
        />

        <ImageView
            android:id="@+id/camera_left_masque"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="-2dp"
            android:src="@drawable/ic_left_masque_photo"
            android:layout_below="@id/camera_top_masque"
        />

        <ImageView
            android:id="@+id/camera_right_masque"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_right_masque_photo"
            android:layout_marginRight="-2dp"
            android:layout_below="@id/camera_top_masque"
            android:layout_alignParentRight="true"
        />

         <ImageView
            android:id="@+id/camera_bottom_masque"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_bottom_masque_photo"
            android:layout_alignParentBottom="true"
        />
</RelativeLayout>