Xamarin C#将视图宽度设置为Android屏幕的百分比

Tsa*_*res 4 c# android xamarin

我有这个按钮,我希望屏幕宽度的25%,和方形.我已经看到了一些制作网格的方法,但效果不佳.有人对此事有任何意见吗?还需要描述更多的背景吗?

Che*_*ron 8

这些Android.Support.Design包还提供了一个很好的新布局类型PercentRelativeLayout.

您可以通过将Xamarin.Android.Support.PercentNuGet包添加到项目中来获取它.

这将使您能够添加PercentRelativeLayout到您的布局,如:

<android.support.percent.PercentRelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"/>
     <ImageView
         app:layout_widthPercent="50%"
         app:layout_heightPercent="50%"
         app:layout_marginTopPercent="25%"
         app:layout_marginLeftPercent="25%" />
     <!-- more views here -->
</android.support.percent.PercentRelativeLayout>
Run Code Online (Sandbox Code Playgroud)

您可以在Google API文档中找到有关此布局的更多信息.