首页 > 解决方案 > 以编程方式设置 LinearLayout 背景资源比例类型

问题描述

我有一个线性布局,当我想以编程方式输入 TileXY 背景图像时,我可以这样做:

ImageButton.SetImageBitmap(BitmapFactory.DecodeFile(Button1ImageURI));
Bitmap temp = BitmapFactory.DecodeFile(Button1ImageURI);
BitmapDrawable bitmapDrawable = new BitmapDrawable(Resources, temp);
bitmapDrawable.SetTileModeXY(Shader.TileMode.Repeat, Shader.TileMode.Repeat);
MainLinearLayout.Background = bitmapDrawable;

我不知道我怎么能做同样的事情,但这次我希望bitmapDrawableLinearLayout中的ScaleType.FitCenter

我不确定我该怎么做,如果我没有在 BitmapDrawable 中放置SetTileModeXY,则MainLinearLayout中的背景使用FitXY进行缩放,但我想在 FitCenter 中进行缩放

标签: androidxamarinxamarin.androidandroid-linearlayout

解决方案


为什么要将图像LinearLayout设置ImageView为. 将图像设置为源并使用 ScaleType?LinearLayoutLinearLayoutImageView


推荐阅读