Android:定位图片?

时间:2011-04-13 14:58:18

标签: java android android-layout

如何在以下布局中定位图像...

|----------------------|
|                      |
|                      |
|   I             I    |
|                      |
|                      |
|                      |
|                      |
|                      |
|   I             I    |
|                      |
|                      |
------------------------

每个I =一个图像视图。

3 个答案:

答案 0 :(得分:1)

将主布局设置为水平。将两个新布局Layout1,Layout2添加到mainlayout。将它们都设置为veritcal布局。将2个图像视图添加到layout1,将2个图像视图添加到layout2。

答案 1 :(得分:1)

您可以使用TableLayout,RelativeLayout或嵌套的LinearLayouts。所有图像的大小是否相同,您希望它们填满屏幕吗?

答案 2 :(得分:1)

试试这个:

<?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">
    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon"
        android:id="@+id/imageView1" android:layout_width="wrap_content"
        android:layout_alignParentLeft="true" android:layout_alignParentTop="true"></ImageView>
    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon"
        android:id="@+id/imageView2" android:layout_width="wrap_content"
        android:layout_alignParentRight="true" android:layout_alignParentTop="true"></ImageView>
    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon"
        android:id="@+id/imageView3" android:layout_width="wrap_content"
        android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"></ImageView>
    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon"
        android:id="@+id/imageView4" android:layout_width="wrap_content"
        android:layout_alignParentRight="true" android:layout_alignParentBottom="true"></ImageView>
</RelativeLayout>

如果你想从边缘拉入图像,只需将android:layout_margin *属性应用于各个ImageView控件。

相关问题