我希望实现类似于以下的东西:
注意三角形右侧的图像图案是如何重复的,直到它到达屏幕边缘。此外,三角形实际上不是三角形(即图像不会是简单的形状),因此请注意这一点。 我对 Android 很陌生,知道在 iOS 中可以设置图像的一部分重复。我不确定这是否也适用于 android,如果是如何?如果不是,那么推荐的方法是什么?
最佳答案
要重复图像,您可以为此位图设置 TileMode。要在您的案例中将其移动到右侧,您可以定义一个图层列表可绘制对象并为其项目提供一个 left 属性:
tile_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<bitmap android:src="@drawable/tile_start" android:gravity="left|bottom"/>
</item>
<item android:left="60px">
<bitmap android:src="@drawable/tile" android:tileMode="repeat"/>
</item>
</layer-list>
只是一些布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:background="@drawable/tiled_background" />
</LinearLayout>
关于Android - 使图像的一部分在 android 中可重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26631966/