我想画一条虚线.我现在用这个来表示实线:

LinearLayout divider = new LinearLayout( this );
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, 2 );
divider.setLayoutParams( params );
divider.setBackgroundColor( getResources().getColor( R.color.grey ) );

我需要这样的东西,但不是实心的,而是点的.我希望避免在透明布局和实体布局之间交替使用数百种布局.

推荐答案

没有java代码:

drawable/dotted.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

    <stroke
       android:color="#FF00FF"
       android:dashWidth="10px"
       android:dashGap="10px"
       android:width="1dp"/>
</shape>

view.xml:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:src="@drawable/dotted"
    android:layerType="software" />

Effect: enter image description here

Android相关问答推荐

在Android Studio中陷入了不兼容的Gradle版本的循环

显示本地房间数据库中未保存的项目的动态列表

Android设备.Net Maui上的mp3文件列表

我如何剪裁一个可由另一个合成的

这款应用与最新版本的Android不兼容.在Android 14中

如何在Android Studio的LinearLayout中禁用阴影

将DiffUtils用于Android上的Recrecerview适配器

学习Kotlin问题.无法理解Modifier参数

如何在 compose android中将图像覆盖在另一个图像上

Jetpack Compose 使用 SavedStateHandle 发送返回结果不适用于 ViewModel 中注入的 SavedStateHandle

使用 Gadle kotlin 为多模块 Android 代码库设置 jacoco

通知使用默认语言,屏幕显示多种语言,同时通过 AppCompatDelegate 设置应用程序语言

Kotlin 协程、 retrofit 、android

在 Jetpack Compose 中重用具有重复代码的列

观察软键盘可见性,打开/关闭 Jetpack Compose

react 从输入中找到路径'lib/arm64-v8a/libfbjni.so'的本机2个文件

如何在 react native 应用程序中显示复选框?当它在 android 模拟器中可见时

有人可以向我解释这两个结果有什么区别吗?

如何在 TextButton 中分隔文本和图标

这是 let 函数的正确用法吗?