【发布时间】:2016-05-17 11:35:29
【问题描述】:
我想将位图设置为视图背景而不进行拉伸,并且我不想将视图宽度和高度更改为换行内容。我想将视图的宽度和高度保持为匹配父级。我设置了如下视图的背景,其中 mDrawingView 是扩展 View 的自定义视图。
Bitmap tempBitmap = BitmapFactory.decodeFile(copy.getAbsolutePath());
mDrawingView.setBackground(new BitmapDrawable(getResources(), tempBitmap));
我的布局文件如下所示,
<MyPackageName.DrawingView
android:id="@+id/drawing_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"/>
请注意,我没有使用 imageview。
请给我建议?
【问题讨论】:
-
请check documentation here 使用默认可用的秤。意识到当在不同的画布中绘制不同的形状(正方形不能完全填满圆形等)时,您的视图会增加,或者不会使用内部的全部区域。
-
backgrounds被缩放以填充视图。因此,如果视图(很可能)与背景的纵横比不同,则会被拉伸。我想你可能想改用 9 补丁。 -
在我的情况下,我从画廊中动态选择图像。它不是静态图像@BobMalooga
标签: android view bitmap scaling