2013-03-29 9 views
3

J'ai 2 image que je veux mettre une image sur une autre mon xml suitimage sur une autre image

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

mise en page ressemble à ce

enter image description here

Je veux cette première image sur cette seconde image. Aussi, on dirait que cette première image se trouve sur la deuxième image

+1

utilisation de la mise en page ralative –

+0

utilisation disposition relative + mise en page de cadre ou relativelayout seul.! – k0sh

Répondre

2

Modifier le LinearLayout à RelativeLayout, changer l'emplacement des 2 images.

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

Je ne sais pas pourquoi les gens downlon m'a voté je suis nouveau ici c'est pourquoi j'ai demandé cette – Anirban

2

Changez Layout Linear en Relative ou FramLayout et ajoutez Margin Top dans les vues. En disposition relative chaque contrôle Automatiquement sur son contrôle ci-dessus. Essayez le code ci-dessous.

<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

Questions connexes