我建立了一個Android應用程序中,我有3個ImageView
正穿過一個LinearLayout
橫放ImageViews,他們被安置了android:layout_width="0dp"
和android:layout_weight="1"
,使得他們有一個即使在佈局蔓延。我怎樣才能均勻地間隔開我的RelativeLayout的
現在我要切換到使用RelativeLayout
(因爲我想重疊另一個形象,不能用一個LinearLayout
來完成),所以我要開始複製具有相同的效果3 ImageView
小號均勻分佈/跨父級佈局縮放,但我不知道如何實現這一點。
我覺得我需要利用android:scaleType
的......也許居中裁剪:
縮放圖像均勻(保持圖像的長寬比),這樣的兩個維度(寬度和高度)圖像將等於或大於視圖的相應尺寸(減去填充)。
這聽起來不錯,但我似乎無法得到它的工作吧... 任何關於我怎麼會做到這一點甚至可以跨越我的RelativeLayout
傳播ImageView
思想?
的代碼片斷現在:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="@+id/dragcircle"
android:layout_width="wrap_content"
android:tag="circle"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
android:src="@drawable/circle" />
<ImageView
android:id="@+id/dragsquare"
android:layout_width="wrap_content"
android:tag="square"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/dragcircle"
android:adjustViewBounds="false"
android:src="@drawable/square" />
<ImageView
android:id="@+id/dragtriangle"
android:layout_width="wrap_content"
android:tag="triangle"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/dragsquare"
android:adjustViewBounds="false"
android:src="@drawable/triangle" />
注:我無法找到相同的約束,因爲這對一個SO一個問題。有一些問題,如:
Android: how evenly space components within RelativeLayout? 和 android RelativeLayout, equal spacing?
但如果你檢查出的細節,你會發現他們是誰,有沒有考慮LinearLayout
爲相等的間距和切換的選項的人佈局類型最終成爲解決方案。我有,我用它,但它沒有做工作適合我,因爲我需要重疊的圖像:
注意的例子,我有3個ImageView
s的基本形狀,但我也有一個4 日ImageView
(它開始隱藏),它與中間的一個重疊。這就是爲什麼我必須使用RelativeLayout
爲什麼不使用relativeLayout,並在其內部使用LinearLayout(爲了使用'layout_weigt')選項,然後可以在父佈局(這是relativeLayout)中重疊新的imageview – Houcine
該解決方案不會使重疊的圖像與它將要重疊的圖像成比例地縮放。 – goto10