2017-06-16 62 views
-2

我想使圖像在axml中的佈局右端角落變得粘稠。我想在Android Xamarin佈局中爲原生App製作圖像粘性。我使用axml進行佈局渲染

+2

我們希望你嘗試自己**編寫代碼**。在[**做更多的研究**之後](https://meta.stackoverflow.com/q/261592/1011527)如果你有問題**發佈你已經嘗試了**的**明確的解釋不工作**並提供[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。閱讀[如何問](http://stackoverflow.com/help/how-to-ask)一個很好的問題。請務必[參觀](http://stackoverflow.com/tour)並閱讀[this](https://meta.stackoverflow.com/q/347937/1011527)。 –

回答

1

編輯

我現在認識到OP需要Xamarin的Android。這是爲Xamarin Forms編寫的。 :)

檢查這個問題,因爲這是一個可能的重複: Set the absolute position of a view

-

嘗試的絕對佈局。

<AbsoluteLayout> 
    <!--If You have other content, like a stacklayout, put it before the image (like below)--> 

    <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"> 
     <!--Content Here --> 
    </StackLayout 

    <Image Source="YOUR IMAGE SOURCE" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="1,1,0.2,0.2" /> 
</AbsoluteLayout> 

讓我來解釋絕對佈局是如何工作的。

所以絕對佈局可以讓你把東西放在彼此之上(或者只是設置一個靜態位置)。

絕對佈局界限的工作如下: (位置X開始,位置Y開始,寬度,高度)。 所以通過輸入(0,0,1,1),我告訴它從0,0開始,寬度和高度應該與窗口大小相同。如果我要這樣做(0.5,0.5,0.2,0.2),那麼我會告訴它從左側開始向下一半,並使對象的總窗口大小爲0.2。

參考文獻: https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/absolute-layout/

希望這有助於

+0

但絕對佈局。已棄用。有沒有其他的選擇? –

+0

我的錯誤。我以爲你想要Xamarin Forms,而不是Android。 – Gerrit

+0

@SudiptoSarkar嘗試檢查這些答案: https://stackoverflow.com/questions/38794796/whats-alternative-to-deprecated-absolutelayout-in-android https://stackoverflow.com/questions/3539349/alternative- to-absolutelayout-in-android – Gerrit