2012-06-08 97 views
1

我正在使用LinearLayout水平放置兩個ImageView。我有圖像放在ImageView。現在我需要在ImageView上的圖片上添加一個小圖片。我看過很多帖子,但都是RelativelayoutFramelayout。這是我用過的XML代碼段。Android:在ImageView上通過圖像顯示圖像

<LinearLayout 
    android:id="@+id/relativeLayout2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/imgmode31" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="10dp" 
     android:adjustViewBounds="true" 
     android:maxHeight="180dp" 
     android:maxWidth="140dp" 
     android:scaleType="fitXY" 
     android:src="@drawable/i5" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/imgmode32" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:longClickable="false" 
     android:maxHeight="180dp" 
     android:maxWidth="280dp" 
     android:scaleType="fitXY" 
     android:src="@drawable/i1" > 
    </ImageView> 

</LinearLayout> 

任何幫助將不勝感激。

回答

1

這正是線性佈局應該防止的。但是,您可以使用負填充覆蓋下一個元素的位置。這個問題就是在不同的屏幕密度上發生的。

我認爲這是表面視圖的意思。它在整個屏幕上提供透明的繪圖表面,讓您可以在其他視圖的頂部繪製。

最後一個想法是將您的第一個圖像放置在線性佈局內的框架佈局中。然後,您可以使用填充將您的疊加圖像添加到框架佈局以定位它。

0

A LinearLayout線性地放置元素,一個接一個。如果要將元素放在另一個元素的上面,則需要使用FrameLayoutRelativeLayout

如果您將LinearLayout更改爲FrameLayout,您應該看到兩個重疊的ImageView

1

你可以用相對佈局

<RelativeLayout 
android:id="@+id/relativeLayout2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" > 
    <ImageView  
    android:layout_height="wrap_content"  
    android:layout_width="wrap_content" 
    android:adjustViewBounds="true" 
    android:scaleType="fitXY" 
    android:src="@drawable/i5" 
    android:id="@+id/imgmode31" 
    android:maxHeight="180dp" 
    android:maxWidth="140dp"> 
    </ImageView> 
    <ImageView  
    android:layout_height="wrap_content"  
    android:layout_width="wrap_content" 
    android:scaleType="fitXY" 
    android:longClickable="false" 
    android:adjustViewBounds="true" 
    android:src="@drawable/i1" 
    android:id="@+id/imgmode32" 
    android:maxHeight="180dp" 
    android:maxWidth="280dp"> 
    </ImageView> 
</RelativeLayout> 

輕鬆地做到這一點,如果你想ImagView互相重疊,然後讓他們HeightWidth同樣,你也可以把任何ImageView在前面的運行

+0

-1表示醜陋的格式,但+1表示正確的答案。我會離開你在0! – Justin

+0

@Justin感謝您指出我的格式,因爲即使我不知道我粘貼了這樣不好的格式化代碼。可能是我從我的手機中完成的。 – Siddhesh