2014-11-04 6 views
2

У меня есть два imageviews, что я хотел бы установить вторую ImageView на первое изображение, как показано ниже изображения:установить ImageView над другим ImageView - XML ​​

enter image description here

первое изображение:

enter image description here

второе изображение (момент):

enter image description here

Как я могу это сделать?

я написал ниже кодов, но он не работает нормально:

<ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true"  
     android:scaleType="fitXY" 
     android:src="@drawable/ic_moment" 
     /> 

    <ImageView 
     android:id="@+id/img_view_item_main_list" 
     android:layout_width="fill_parent" 
     android:layout_height="220dp" 
     android:scaleType="fitXY"  
     android:src="@drawable/testtesttest" /> 

+0

http://stackoverflow.com/questions/11468146/android-imageview-over-imageview –

+0

Используйте 'FrameLayout' или' RelativeLayout'. – Piyush

+0

Пожалуйста, проверьте эту ссылку, это может помочь вам [Link] [1] [1]: http://stackoverflow.com/questions/11959841/how-to-place-an-imageview-on-top -of-another-imageview-in-android –

ответ

4

Используйте Framelayout или использовать слияния тег

например:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/t" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 

</FrameLayout> 

второе изображение приходит на верхней

+0

это тоже будет отлично! –

+0

Если вы хотите «Специальное» изображение в правом нижнем углу, просто добавьте 'android: layout_gravity =" bottom | right "' – paakjis

3

пытаются сделать что-то вроде как следует

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/white" > 

    <ImageView 
     android:id="@+id/inside_imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dip" 
     android:layout_marginTop="5dip" 
     android:src="@drawable/frame" /> 

     <ImageView 
     android:id="@+id/outside_imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/inside_imageview" 
     android:layout_alignBottom="@id/inside_imageview" 
     android:layout_alignLeft="@id/inside_imageview" 
     android:layout_alignRight="@id/inside_imageview"    
     android:scaleType="fitXY" /> 
    </RelativeLayout> 

Также вы можете посетить how to place an image over another one on android app?

2

Попробуйте этот путь, надеюсь, это поможет вам решить вашу проблему ,

Возьмите FrameLayout в качестве родительского и установите верхнее изображение макета гравитационного верха и пусть.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitXY" 
     android:src="@drawable/ic_moment" /> 

    <ImageView 
     android:id="@+id/img_view_item_main_list" 
     android:layout_width="wrap_content" 
     android:layout_height="220dp" 
     android:scaleType="fitXY" 
     android:layout_gravity="top|left" 
     android:src="@drawable/testtesttest" /> 

</FrameLayout> 
2

попробовать, как это,

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/ic_launcher" > 

    <ImageView 
     android:id="@+id/img_view_item_main_list" 
     android:layout_width="fill_parent" 
     android:layout_height="220dp" 
     android:adjustViewBounds="true" 
     android:scaleType="fitXY" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitXY" 
     android:layout_gravity="top|left" 
     android:src="@drawable/ic_launcher" /> 

</FrameLayout> 

надеюсь, что это поможет вам

1

Используйте его, как это.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:scaleType="center" 
    android:src="@drawable/golden_gate" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dip" 
     android:layout_gravity="center_horizontal|bottom" 
     android:padding="12dip" 
     android:src="@drawable/logo"/> 

</FrameLayout> 
0

Вы можете использовать что-то вроде ниже макете

<RelativeLayout 
android:layout_width="match_parent" // This you can change as per your requirement 
android:layout_height="match_parent" // This you can change as per your requirement 
> 

<ImageView 
    android:id="@+id/img_view_item_main_list" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scaleType="fitXY"  
    android:src="@drawable/testtesttest" 
    android:layout_centerInParent="true" 
    /> 

</RelativeLayout> 

Надежда это будет полезно для вас.

0

Вы также можете использовать слой-лист в качестве рисунка и сделать его фоном вашего изображения.

my_image.xml> сохранить его в папке вытяжке

<?xml version="1.0" encoding="utf-8"?> 
<layer-list 
xmlns:android="http://schemas.android.com/apk/res/android" > 
<item 
    android:drawable="your_image_1" 
    android:top="dimension" 
    android:right="dimension" 
    android:bottom="dimension" 
    android:left="dimension" /> 
<item 
    android:drawable="your_image_2" 
    android:top="dimension" 
    android:right="dimension" 
    android:bottom="dimension" 
    android:left="dimension" /> 
</layer-list> 

и с вашей точки зрения изображения.

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scaleType="fitXY" 
    android:layout_gravity="top|left" 
    android:drawable="@drawable/my_image"/> 

таким образом вы можете добавить несколько изображений, что сделает его более интересным. Просто убедитесь, что в формате png и установите фон изображения как прозрачный.

Смежные вопросы