Android - 使图像的一部分在 android 中可重复?

标签 android image user-interface imageview

我希望实现类似于以下的东西: enter image description here

注意三角形右侧的图像图案是如何重复的,直到它到达屏幕边缘。此外,三角形实际上不是三角形(即图像不会是简单的形状),因此请注意这一点。 我对 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>

enter image description here

关于Android - 使图像的一部分在 android 中可重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26631966/

相关文章:

android - 引用模块中的资源

android - SDCard 不准确

Java SWT 按钮图像不刷新

c# - 在图像控件中显示 byte[]

javascript - 加载没有图像的网站以提高效率

jquery - 以编程方式取消选中 jQuery UI 复选框按钮

java - 编译时出现 SQLiteException : no such column itemId: ,:

Android 从收件箱中获取短信,优化了读取所有消息并将它们分组的方式

amazon-web-services - 登录页面 Cognito 的自定义

javascript - 使用 jQuery 动态切换和更改 id