2013-03-29 127 views
3

我有2图像我想提出一个形象在我的另一个XML如下图像在另一个图像

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

<ImageView 
    android:id="@+id/imgThumb" 
    android:layout_width="60dip" 
    android:layout_height="80dip" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="20sp" 
    android:src="@drawable/bg" /> 

<TextView 
    android:id="@+id/imgText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="5dip" 
    android:ellipsize="marquee" 
    android:singleLine="true" 
    android:text="test string" 
    android:textColor="#000000" 
    android:textSize="10dip" 
    android:visibility="gone" /> 

<View 
    android:layout_width="fill_parent" 
    android:layout_height="30sp" 
    android:background="@drawable/shelf" /> 

布局看起来像这样

enter image description here

我想这第一个图像在这第二个图像。因此,它看起来像这第一个图像站在第二个图像

+1

使用相对布局 –

+0

仅使用相对布局+框架布局或relativelayout。 – k0sh

回答

2

更改的LinearLayout到RelativeLayout的,切换2个图像的位置。

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

<View 
    android:id="@+id/shelf" 
    android:layout_below="@+id/imgThumb" 
    android:layout_width="fill_parent" 
    android:layout_height="30sp" 
    android:background="@drawable/shelf" /> 

<ImageView 
    android:id="@+id/imgThumb" 
    android:alignParentTop="true" 
    android:layout_width="60dip" 
    android:layout_height="80dip" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="20sp" 
    android:src="@drawable/bg" /> 
+2

我不知道为什么人们downlon投了我我是新来的这就是为什么我问这个 – Anirban

2

将布局线性更改为相对或FramLayout,并在视图中添加边距顶部。 在相对布局中,每个控件都在其上方自动控制。 请尝试以下代码。

<ImageView 
    android:id="@+id/imgThumb" 
    android:layout_width="60dip" 
    android:layout_height="80dip" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="20sp" 
    android:src="@drawable/abc" /> 

<TextView 
    android:id="@+id/imgText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="5dip" 
    android:ellipsize="marquee" 
    android:singleLine="true" 
    android:text="test string" 
    android:textColor="#000000" 
    android:textSize="10dip" 
    android:visibility="gone" /> 

<View 
    android:layout_width="fill_parent" 
    android:layout_height="30sp" 
    android:layout_marginTop="20sp" 
    android:background="@drawable/ic_launcher" /> 

1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" > 

    <ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="138dp" 
    android:layout_marginTop="142dp" 
    android:src="@drawable/ic_launcher" /> 

    <ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView1" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="16dp" 
    android:src="@drawable/ic_launcher" /> 

    <ImageView 
    android:id="@+id/imageView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView2" 
    android:layout_alignTop="@+id/imageView2" 
    android:layout_marginTop="15dp" 
    android:src="@drawable/ic_launcher" /> 

    </RelativeLayout> 

enter image description here