- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个平铺位图用作View
背景。这个 View
,比方说,有android:layout_height="wrap_content"
。问题是背景中使用的位图的高度参与了 View 的测量,增加了 View
高度。当 View
的内容大小小于用作平铺背景的位图的高度时,可以注意到这一点。
让我举个例子。瓦片位图:
可绘制位图(tile_bg.xml
):
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/tile"
android:tileMode="repeat"/>
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tile_bg"
android:text="@string/hello"
android:textColor="#000000" />
</LinearLayout>
它的样子:
TextView
的高度最终成为位图的高度。我所期望的是位图被裁剪为 View
的大小。
有什么办法可以实现吗?
注意事项:
View
设置固定高度,这取决于子项(我在 ViewGroup
中使用它)View
的大小小于位图的大小时,就会出现这种奇怪的行为,否则位图会重复并正确裁剪(即,如果 View 大小为 1.5 x 位图的大小,您最终看到的是位图的 1.5 倍)。最佳答案
您需要一个从 getMinimumHeight() 和 getMinimumWidth() 返回 0 的自定义 BitmapDrawable。这是一个我命名为 BitmapDrawableNoMinimumSize 的函数:
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
public class BitmapDrawableNoMinimumSize extends BitmapDrawable {
public BitmapDrawableNoMinimumSize(Resources res, int resId) {
super(res, ((BitmapDrawable)res.getDrawable(resId)).getBitmap());
}
@Override
public int getMinimumHeight() {
return 0;
}
@Override
public int getMinimumWidth() {
return 0;
}
}
当然你不能(据我所知)在 XML 中声明自定义可绘制对象,所以你必须这样实例化和设置 TextView 的背景:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BitmapDrawable bmpd =new BitmapDrawableNoMinimumSize(getResources(), R.drawable.tile);
bmpd.setTileModeX(TileMode.REPEAT);
bmpd.setTileModeY(TileMode.REPEAT);
findViewById(R.id.textView).setBackgroundDrawable(bmpd);
}
当然,您从布局 xml 中删除了背景属性:
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Testing testing testing"
android:textColor="#000000" />
我已经测试过了,它似乎有效。
关于android - 平铺背景正在插入它的 View 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8842484/
我正在尝试制作一种能够解决拼贴问题中的大图 block 集的算法。现在它能够根据宽度和高度找到正确的 Tiles 来放置,但是在使其正确递归方面存在一些问题。 如您所见,这个想法是,在放置的每个图 b
有什么方法可以轻松地平铺 mdi parent 的所有表单 child 吗?我正在寻找 windows 提供的大部分功能,瓷砖级联。有谁知道一个简单的方法? 最佳答案 试试这些... // Tile
我有一个大 jpg,其分辨率为 x * 256/x * 256。我想将此图像切割为 256x256 的图块,命名约定为 {zoom}-{x}-{y}.jpg。过去我使用 ZoomifyExpress
如何使用ImageMagick平铺图像?我认为我不能使用montage,因为我希望将列偏移原始图像高度的50%。 展示我正在尝试做的事可能更容易: 从...开始: 结尾为: 谢谢! 最佳答案 感谢Fr
是否可以在 XNA 中平铺图像以使其填满整个矩形?我试过用谷歌搜索这个主题,但我找不到任何似乎有用的东西(虽然我可能遗漏了一些明显的东西)。我找到了 this MSDN page ,但我似乎无法让它工
我无法找到答案,为什么我为图 block map 制作的图 block 表在使用 libGDX 在屏幕上移动时会创建垂直白线和不稳定的水平线。 这是显示白色垂直线的视频:https://www.you
有谁知道 GitHub Java version of Tiled 中如何临时支持视差图层吗?工作正常吗? 它可以编译,并且执行得很好。但是,如果我将图层设置为viewplane distance 0
在我制作的平台游戏中,我需要加载图 block 才能创建关卡,但在下面的代码中我似乎遇到了问题。它说我在这部分有一个错误: String[] skips = skip.split(" "); 但对我来
使用 pdfimages 提取图像和 mupdf/mutool到目前为止工作正常。 使用 FreePDF 生成的 PDF 中的图像总是被切片,因此一个图像会生成多个图像文件。 有什么技巧可以避免这种情
我正在尝试使用 Tiled 编写基于 rts-like-tile 的游戏和 slick2d。 我不知道如何处理多图 block 对象,例如建筑物,如何创建、保存等等。移动它们。 最佳答案 一种解决方案
我想用一张图片来编写一个平铺 map 。它应该是一个 5x5 的小图片区域。我写了一些带有 2 个嵌套循环的 Javascript 代码。使用此解决方案,仅打印 1 张图片。当我在第二个循环中删除 b
我正在尝试使用 Slick2D 和 Tiled Map Editor 制作一个基本的 2D 游戏。我已经弄清楚如何使用 TileProperties 进行基本的碰撞检测,但我不确定对象如何与 map
我正在尝试创建一个无限滚动的分页 UIScrollView 我一直在关注 Advanced UIScrollView Techniques来自 WWDC 2010 的视频,但是我不确定如何为分页 UI
好吧,假设我有一个像本网站一样的冷却平铺背景。 http://www.leeslights.com/colors-shapes-sizes-and-prices.html 我将如何使图像平铺到浏览器,
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
我是一名优秀的程序员,十分优秀!