开发者

Android: Positioning images?

开发者 https://www.devze.com 2023-02-25 11:46 出处:网络
How would I position images in the following layout... ----------------------| II| 开发者_开发百科|

How would I position images in the following layout...

|----------------------|
|                      |
|                      |
|   I             I    |
|                      |
|          开发者_开发百科            |
|                      |
|                      |
|                      |
|   I             I    |
|                      |
|                      |
------------------------

Where each I = an imageview.


You can use a TableLayout, a RelativeLayout or nested LinearLayouts. Are all the images the same size and do you want them to fill the screen?


Set your main layout to horizontal. Add two new layouts, Layout1, Layout2 to your mainlayout. Set them both to veritcal layout. Add 2 imageviews to layout1 and 2 imageviews to layout2.


Try this:

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

if you want to pull the images in from the edges, just apply android:layout_margin* attributes to the individual ImageView controls.

0

精彩评论

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