2012-01-16 48 views

回答

0

難不幫你的佈局XML代碼。話雖如此,當你看到「一個在另一個之上」時,你需要考慮FrameLayout

0

使用的FrameLayout,並設置相同的背景圖像,然後用重力佈局設置爲左或右或中間添加在上面的圖像。

1

當使用相對佈局的唯一選擇這樣做,是在佈局,以中心組圖片,但如果你開始添加更多的元素,比如上面的一些文本/低於任何圖像,結果會不會像預期。

所以我的建議是以編程方式進行。您可以定義一個視圖並覆蓋onDraw()方法。然後,您將通過兩個ImageView(或BitmapFactory)加載位圖。然後將其繪製到所需位置的畫布上。要找出每個圖像的中心,您可以使用您從View method getDrawingRect得到Rect class應用(使大小計算)的佈局屬性後,,或通過手(創建一個矩形與您加載的位圖的尺寸德使用BitmapFactory)

其他替代方法是使用LayerDrawable並定義圖像位置以使它們居中(您需要事先知道圖像尺寸)。

0

在創建新sublayout代替,則可能會使該ImageViews在各方面調整和設置scaleType屬性類似center

<ImageView 
    android:id="@+id/circle_a" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/..." 
    android:scaleType="center"/> 

<ImageView 
    android:id="@+id/circle_b" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/..." 
    android:layout_alignTop="@+id/circle_a" 
    android:layout_alignBottom="@+id/circle_a" 
    android:layout_alignLeft="@+id/circle_a" 
    android:layout_alignRight="@+id/circle_a" 
    android:scaleType="center" /> 

這將給circle_b ImageView的實際尺寸相同circle_a,但設置適當的scaleType將防止圖像被拉伸或未對齊。

//編輯:UPS,我的意思是說center ...糾正。

相關問題