是否可以通过使用其他元素值的百分比来设置诸如高度、宽度和边距之类的值。例如,让一个元素的宽度是另一个元素的一半。
当这是以编程方式或在 axml 代码中时,我不介意。
目前,我一直在尝试像这样以编程方式进行操作:
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
var metrics = Resources.DisplayMetrics;
var widthInDp = ConvertPixelsToDp(metrics.WidthPixels);
var heightInDp = ConvertPixelsToDp(metrics.HeightPixels);
SetContentView (Resource.Layout.Main);
//Set title width as 98% of total width
ImageView title_img = FindViewById<ImageView> (Resource.Id.apptitle);
LinearLayout baseparent = FindViewById<LinearLayout> (Resource.Id.baselayout);
title_img.LayoutParameters.Width = (baseparent.Width / 100) * 98 ;
//Set welcome width as half of title width
ImageView welcome_img = FindViewById<ImageView> (Resource.Id.welcome);
welcome_img.LayoutParameters.Width = title_img.Width/2;
}
private int ConvertPixelsToDp(float pixelValue)
{
var dp = (int) ((pixelValue)/Resources.DisplayMetrics.Density);
return dp;
}