android - 以编程方式设置 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;
我不知道我怎么能做同样的事情,但这次我希望bitmapDrawable到LinearLayout中的ScaleType.FitCenter。
我不确定我该怎么做,如果我没有在 BitmapDrawable 中放置SetTileModeXY,则MainLinearLayout中的背景使用FitXY进行缩放,但我想在 FitCenter 中进行缩放
解决方案
为什么要将图像LinearLayout
设置ImageView
为. 将图像设置为源并使用 ScaleType?LinearLayout
LinearLayout
ImageView
推荐阅读
- r - 在 R 中修复裁剪的 Kable 图像
- graphql - 盖茨比页面中的 GraphQL 依赖查询
- google-sheets - 按月、按笼子查询费用、汇总和总和
- android - 在布局和通知栏中都有 Exoplayer 控件?
- php - 全新安装后未加载 Laravel Spark 注册视图
- c++ - Vector assign() 导致 back() 出现问题
- powershell - Powershell 按 MM/DD/YY、HH:MM AM/PM 排序
- arrays - 当某些键仅存在于几个数组中时,不确定使用 jq 过滤一组 json 数组的最有效方法 - //?
- java - 如何创建一个访问我的项目文件夹之外的文件的 Spring bean?
- javascript - 在Javascript控制台中输出姓氏的第一个字母以及大写字母的首字母?