AbsoluteLayout 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將子項目放在絕對位置。
public class AbsoluteLayout : Xamarin.Forms.Layout<Xamarin.Forms.View>, Xamarin.Forms.IElementConfiguration<Xamarin.Forms.AbsoluteLayout>
type AbsoluteLayout = class
inherit Layout<View>
interface IElementConfiguration<AbsoluteLayout>
- 繼承
-
System.ObjectAbsoluteLayout
- 實作
備註
應用程式開發人員可以根據傳遞給 SetLayoutFlags(BindableObject, AbsoluteLayoutFlags) 方法的值,提供比例座標、裝置座標或兩者的組合,AbsoluteLayoutFlags來控制子元素的位置。 提供其中一個比例 AbsoluteLayoutFlags 列舉值時,介於 0.0 和 1.0 之間的對應 X 或 Y 自變數一律會導致子系完全顯示在螢幕上。 也就是說,您不需要減去或新增子系的高度或寬度,才能以 的左、右、上或底端 AbsoluteLayout顯示。 對於未按比例指定的寬度、高度、X 或 Y 值,應用程式開發人員會使用裝置相依單位來尋找及調整子元素的大小。
下列範例示範如何使用 AbsoluteLayout 具有比例位置自變數的 。
Label header = new Label
{
Text = "AbsoluteLayout Demo",
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
HorizontalOptions = LayoutOptions.Center
};
AbsoluteLayout simpleLayout = new AbsoluteLayout
{
BackgroundColor = Color.Blue.WithLuminosity(0.9),
VerticalOptions = LayoutOptions.FillAndExpand
};
topLeftLabel = new Label
{
Text = "Top Left",
TextColor = Color.Black
};
centerLabel = new Label
{
Text = "Centered",
TextColor = Color.Black
};
bottomRightLabel = new Label
{
Text = "Bottom Right",
TextColor = Color.Black
};
// PositionProportional flag maps the range (0.0, 1.0) to
// the range "flush [left|top]" to "flush [right|bottom]"
AbsoluteLayout.SetLayoutFlags(bottomRightLabel,
AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(topLeftLabel,
new Rectangle(0f,
0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
AbsoluteLayout.SetLayoutFlags(centerLabel,
AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(centerLabel,
new Rectangle(0.5,
0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
AbsoluteLayout.SetLayoutFlags(bottomRightLabel,
AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(bottomRightLabel,
new Rectangle(1f,
1f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
simpleLayout.Children.Add(topLeftLabel);
simpleLayout.Children.Add(centerLabel);
simpleLayout.Children.Add(bottomRightLabel);
下列程式代碼範例示範如何藉由指定裝置相依單位來放置兩個標籤。
AbsoluteLayout simpleLayout = new AbsoluteLayout
{
BackgroundColor = Color.Blue.WithLuminosity(0.9),
VerticalOptions = LayoutOptions.FillAndExpand
};
Label header = new Label
{
Text = "Device Units Demo",
TextColor = Color.Black,
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
};
topLeftText = new Label
{
Text = "Left",
TextColor = Color.Black
};
AbsoluteLayout.SetLayoutFlags(topLeftText,
AbsoluteLayoutFlags.None);
AbsoluteLayout.SetLayoutBounds(topLeftText,
new Rectangle(0f, 0f, 100f, 50f));
middleText = new Label
{
Text = "Device-dependent location",
TextColor = Color.Black
};
AbsoluteLayout.SetLayoutFlags(middleText,
AbsoluteLayoutFlags.None);
AbsoluteLayout.SetLayoutBounds(middleText,
new Rectangle(100f, 200f, 200f, 50f));
simpleLayout.Children.Add(topLeftText);
simpleLayout.Children.Add(middleText);
}
下圖顯示 FormsGallery 範例中的 AbsoluteLayout 示範。
適用於 Xamarin 的 XAML。Forms 支援 類別的下列附加屬性AbsoluteLayout:
附加屬性 | 值 |
---|---|
AbsoluteLayout.LayoutBounds | 以逗號分隔的清單,可能具有空格,其值為四個值,指定周框的位置和維度。 清單中的前兩個值必須代表數位。 後者兩個值可以是數位,或字串 「AutoSize」。 |
AbsoluteLayout.LayoutFlags | AbsoluteLayoutFlags列舉值名稱: |
應用程式開發人員可以使用 XAML 來配置 類別的專案 AbsoluteLayout 。 下列範例會將藍色 BoxView 放在 內 AbsoluteLayout:
<AbsoluteLayout VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
<BoxView AbsoluteLayout.LayoutBounds="0.25, 0.25, 0.5, 0.5"
Color="Blue"
AbsoluteLayout.LayoutFlags="All" />
</AbsoluteLayout>
類別 AbsoluteLayout 可以使用比例單位、裝置單位或兩者的組合來配置其子元素。 應用程式開發人員在指定 Rectangle 將定義子專案的版面配置界限的結構時,應該記住下列幾點:
- 對於高度和寬度符合螢幕的專案,範圍 [0,1] 中的比例位置維度代表完全在螢幕上的項目,不論高度、寬度或兩者都是以裝置或比例單位指定。:
- 上述點表示,若要在螢幕右下角指定元素,且半寬和半做為螢幕,且AbsoluteLayoutFlags
All
值為 ,應用程式開發人員會指定 “1.0, 1.0, 0.5, 0.5”。: - 應用程式開發人員可能會不小心造成子元素,其中一或兩個大小維度的子元素會依比例顯示於螢幕外,或完全隱藏,方法是指定沒有足夠空間供子系計算大小的裝置單位位置。
- 周框 Rectangle 結構的每個部分都會根據 AbsoluteLayoutFlags 控制它的值來解譯。 例如,給定的矩形可能會有 X 座標,以裝置單位為單位、以比例單位表示的 Y 座標、以比例單位表示的高度,以及裝置單位的寬度,或任何其他裝置和比例單位的組合。 :
- 使用子系上目前AbsoluteLayoutFlags設定來解譯的矩形,代表部分或全螢幕外周框方塊,例如,如果寬度大於螢幕寬度,可能會產生非預期的結果:
建構函式
AbsoluteLayout() |
初始化 AbsoluteLayout 類別的新執行個體。 |
欄位
LayoutBoundsProperty |
實作代表子項目的配置界限附加屬性。 可在執行階段使用字串 "LayoutBounds" 繫結。 請參閱<備註>。 |
LayoutFlagsProperty |
實作包含子項目的 AbsoluteLayoutFlags 值附加屬性。 |
屬性
AnchorX |
取得或設定任何轉換內中心點的 X 元件 (相對於項目界限)。 這是可繫結屬性。 (繼承來源 VisualElement) |
AnchorY |
取得或設定任何轉換內中心點的 Y 元件 (相對於項目界限)。 這是可繫結屬性。 (繼承來源 VisualElement) |
AutomationId |
取得或設定值,允許自動化架構尋找此項目並與之互動。 (繼承來源 Element) |
AutoSize |
指出子系的寬度或高度大小應該調整為子系原生大小的值。 |
Background |
將子項目放在絕對位置。 (繼承來源 VisualElement) |
BackgroundColor |
取得或設定將會填滿 VisualElement 背景的色彩。 這是可繫結屬性。 (繼承來源 VisualElement) |
Batched |
供 Xamarin.Forms 平台內部使用。 (繼承來源 VisualElement) |
Behaviors |
取得與此元素關聯的行為清單。 這是可繫結屬性。 (繼承來源 VisualElement) |
BindingContext |
取得或設定物件,這個物件包含屬於此 BindableObject 屬性繫結屬性將設為目標的屬性。 (繼承來源 BindableObject) |
Bounds |
取得項目的界限。 (繼承來源 VisualElement) |
CascadeInputTransparent |
取得或設定值,這個值控制子項目在透明度為 |
Children |
取得 AbsoluteLayout 的子項目集合。 |
class |
將子項目放在絕對位置。 (繼承來源 NavigableElement) |
ClassId |
取得或設定值,用來識別語意類似項目的集合。 (繼承來源 Element) |
Clip |
將子項目放在絕對位置。 (繼承來源 VisualElement) |
DisableLayout |
供 Xamarin.Forms 平台內部使用。 (繼承來源 VisualElement) |
Dispatcher |
將子項目放在絕對位置。 (繼承來源 BindableObject) |
EffectControlProvider |
供 Xamarin.Forms 平台內部使用。 (繼承來源 Element) |
Effects |
套用至此項目的效果清單。 (繼承來源 Element) |
FlowDirection |
取得或設定配置流程方向。 (繼承來源 VisualElement) |
GestureController |
取得檢視的軌跡控制器。 (繼承來源 View) |
GestureRecognizers |
與此檢視建立關聯的筆勢辨識器集合。 (繼承來源 View) |
Height |
取得此項目的目前呈現高度。 這是唯讀的可繫結屬性。 (繼承來源 VisualElement) |
HeightRequest |
取得或設定此項目所需的高度覆寫項。 (繼承來源 VisualElement) |
HorizontalOptions |
取得或設定 LayoutOptions,定義如何在配置循環配置項目。 這是可繫結屬性。 (繼承來源 View) |
Id |
取得值,可用來在應用程式執行期間唯一識別項目。 (繼承來源 Element) |
InputTransparent |
取得或設定值,這個值指出是否應該在使用者互動週期中包含此項目。 這是可繫結屬性。 (繼承來源 VisualElement) |
IsClippedToBounds |
取得或設定值,這個值決定 Layout 是否應該將其子系裁剪到其界限。 (繼承來源 Layout) |
IsEnabled |
取得或設定值,這個值指出使用者介面中是否已啟用此項目。 這是可繫結屬性。 (繼承來源 VisualElement) |
IsFocused |
取得值,這個值指出此項目目前是否為焦點。 這是可繫結屬性。 (繼承來源 VisualElement) |
IsInNativeLayout |
供 Xamarin.Forms 平台內部使用。 (繼承來源 VisualElement) |
IsNativeStateConsistent |
供 Xamarin.Forms 平台內部使用。 (繼承來源 VisualElement) |
IsPlatformEnabled |
供 Xamarin.Forms 平台內部使用。 (繼承來源 VisualElement) |
IsTabStop |
取得或設定值,這個值表示此元素是否包含於索引標籤巡覽。 這是可繫結屬性。 (繼承來源 VisualElement) |
IsVisible |
取得或設定值,這個值會決定此項目是否應成為視覺化樹狀結構的一部分。 這是可繫結屬性。 (繼承來源 VisualElement) |
LogicalChildren |
供 Xamarin.Forms 平台內部使用。 (繼承來源 Element) |
Margin |
取得或設定檢視的邊界。 (繼承來源 View) |
MinimumHeightRequest |
取得或設定值,這個值會覆寫項目在配置期間要求的最小高度。 (繼承來源 VisualElement) |
MinimumWidthRequest |
取得或設定值,這個值會覆寫項目在配置期間要求的最小寬度。 (繼承來源 VisualElement) |
Navigation |
將子項目放在絕對位置。 (繼承來源 NavigableElement) |
NavigationProxy |
將子項目放在絕對位置。 (繼承來源 NavigableElement) |
Opacity |
取得或設定套用至項目 (呈現時) 的不透明度值。 這是可繫結屬性。 (繼承來源 VisualElement) |
Padding |
取得或設定 Layout 的內部填補。 (繼承來源 Layout) |
Parent |
取得或設定項目的父項目。 (繼承來源 Element) |
ParentView |
已淘汰.
取得即此項目最接近上階的項目,而此項目是 VisualElement。 (繼承來源 Element) |
Platform |
已淘汰.
將子項目放在絕對位置。 (繼承來源 Element) |
RealParent |
供 Xamarin.Forms 平台內部使用。 (繼承來源 Element) |
Resources |
取得或設定本機資源字典。 (繼承來源 VisualElement) |
Rotation |
取得或設定呈現元素時繞著 Z 軸 (仿射旋轉) 的旋轉 (度)。 (繼承來源 VisualElement) |
RotationX |
取得或設定呈現元素時繞著 X 軸 (透視旋轉) 的旋轉 (度)。 (繼承來源 VisualElement) |
RotationY |
取得或設定呈現元素時繞著 Y 軸 (透視旋轉) 的旋轉 (度)。 (繼承來源 VisualElement) |
Scale |
取得或設定套用至項目的縮放比例。 (繼承來源 VisualElement) |
ScaleX |
取得或設定要套用至 X 方向的小數位數值。 (繼承來源 VisualElement) |
ScaleY |
取得或設定要套用至 Y 方向的小數位數值。 (繼承來源 VisualElement) |
Style |
將子項目放在絕對位置。 (繼承來源 NavigableElement) |
StyleClass |
將子項目放在絕對位置。 (繼承來源 NavigableElement) |
StyleId |
取得或設定使用者定義值來唯一識別項目。 (繼承來源 Element) |
TabIndex |
將子項目放在絕對位置。 (繼承來源 VisualElement) |
TranslationX |
取得或設定項目的 X 轉譯差異。 (繼承來源 VisualElement) |
TranslationY |
取得或設定項目的 Y 轉譯差異。 (繼承來源 VisualElement) |
Triggers |
取得與此項目建立關聯的觸發程序清單。 這是可繫結屬性。 (繼承來源 VisualElement) |
VerticalOptions |
取得或設定 LayoutOptions,定義如何在配置循環配置項目。 這是可繫結屬性。 (繼承來源 View) |
Visual |
將子項目放在絕對位置。 (繼承來源 VisualElement) |
Width |
取得此項目的目前呈現寬度。 這是唯讀的可繫結屬性。 (繼承來源 VisualElement) |
WidthRequest |
取得或設定此項目所需的寬度覆寫項。 (繼承來源 VisualElement) |
X |
取得此項目的目前 X 位置。 這是唯讀的可繫結屬性。 (繼承來源 VisualElement) |
Y |
取得此項目的目前 Y 位置。 這是唯讀的可繫結屬性。 (繼承來源 VisualElement) |
方法
事件
BatchCommitted |
供 Xamarin.Forms 平台內部使用。 (繼承來源 VisualElement) |
BindingContextChanged |
每當 BindingContext 屬性變更時引發。 (繼承來源 BindableObject) |
ChildAdded |
只要將子項目新增至項目時就發生。 (繼承來源 Element) |
ChildRemoved |
只要從項目移除子項目時就發生。 (繼承來源 Element) |
ChildrenReordered |
在 VisualElement 的子系已重新排序時發生。 (繼承來源 VisualElement) |
DescendantAdded |
只要將子項目新增至項目樹狀子目錄時即發生。 (繼承來源 Element) |
DescendantRemoved |
只要從項目樹狀子目錄移除子項目時即發生。 (繼承來源 Element) |
FocusChangeRequested |
供 Xamarin.Forms 平台內部使用。 (繼承來源 VisualElement) |
Focused |
在項目取得焦點時發生。 (繼承來源 VisualElement) |
LayoutChanged |
如果任何子項目的 Bounds 已變更,則會在配置週期結束時發生。 (繼承來源 Layout) |
MeasureInvalidated |
視覺項目配置失效時所引發的事件。 (繼承來源 VisualElement) |
PlatformSet |
已淘汰.
將子項目放在絕對位置。 (繼承來源 Element) |
PropertyChanged |
在屬性變更時引發。 (繼承來源 BindableObject) |
PropertyChanging |
在屬性即將變更時引發。 (繼承來源 BindableObject) |
SizeChanged |
當這個項目的 Width 或 Height 屬性變更值時發生。 (繼承來源 VisualElement) |
Unfocused |
在項目失去焦點時發生。 (繼承來源 VisualElement) |
明確介面實作
IDynamicResourceHandler.SetDynamicResource(BindableProperty, String) |
供 Xamarin.Forms 平台內部使用。 (繼承來源 BindableObject) |
IElementController.SetValueFromRenderer(BindableProperty, Object) |
供 Xamarin.Forms 平台內部使用。 (繼承來源 Element) |
IGestureController.CompositeGestureRecognizers |
供 Xamarin.Forms 平台內部使用。 (繼承來源 View) |
INameScope.RegisterName(String, Object) |
僅供內部使用。 (繼承來源 Element) |
IVisualElementController.EffectiveFlowDirection |
取得平台上項目的有效視覺流程方向,並將地區設定和邏輯流程設定納入考量。 (繼承來源 VisualElement) |
IVisualElementController.InvalidateMeasure(InvalidationTrigger) |
此方法供內部使用。 (繼承來源 VisualElement) |