0

たとえば、別の要素の値のパーセンテージを使用して、高さ、幅、マージンなどの値を設定することは可能ですか? たとえば、ある要素の幅を別の要素の半分にします。

これがプログラムまたは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;
}
4

1 に答える 1