android - 如何在 Android 中制作虚线/虚线?

标签 android

我正在尝试画一条虚线。我现在正在使用它作为实线:

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" />

效果: enter image description here

关于android - 如何在 Android 中制作虚线/虚线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6103713/

相关文章:

android - 如何在android中改变音频的音调而不改变其持续时间(节奏,速度)?

android - 单一布局中的 BottomNavigationBar、Fab Button 和 ActionBar

java - 当应用程序从堆栈中终止时,后台服务将停止

android - 如何在Android中使屏幕保持横向模式

android - 基于 flavor 的gradle依赖版本

java - ListView 随时间更新

java - 接口(interface)函数: Utility to span hierarchies?

android - 如何在android中获取当前的内存使用情况?

android - 将图层列表转换为位图可能不起作用

java - Android 丢失应用程序数据 (/data/data/com.app.app/files)