Android 实现横向、竖向虚线View

效果展示:
在这里插入图片描述

先实现一个虚线框:

<!--在drawable中定义一个dashed_bg.xml-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="1dp"
        android:height="1dp"
        android:color="#60B543"
        android:dashWidth="2dp"
        android:dashGap="2dp" />
    <size
        android:width="0.5dp"
        android:height="100dp" />
</shape>

布局中使用背景:

<!--竖向虚线-->
		<View
            android:layout_width="2dp"
            android:layout_height="13dp"
            android:layout_centerInParent="true"
            android:background="@drawable/dashed_bg" />
<!--横向虚线-->
<View
        android:layout_width="match_parent"
        android:layout_height="1.5dp"
        android:layout_centerInParent="true"
        android:background="@drawable/dashed_bg" />
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 横向竖向滚动的两种解决方法如下: 1. 使用 ScrollView 和 HorizontalScrollView ScrollView 和 HorizontalScrollViewAndroid 中提供的两个滚动视图控件,可以用于实现竖向横向的滚动。它们可以嵌套在布局中,使得布局中的内容可以滚动。 例如,如果想实现一个竖向滚动的布局,可以这样使用: ``` <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 布局内容 --> </ScrollView> ``` 如果想实现一个横向滚动的布局,可以这样使用: ``` <HorizontalScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 布局内容 --> </HorizontalScrollView> ``` 2. 使用 RecyclerView 和 LinearLayoutManager RecyclerView 和 LinearLayoutManager 是 Android 中提供的两个用于实现列表布局的控件,可以用于实现竖向横向的滚动。RecyclerView 可以重复使用 View,从而提高了列表性能。 例如,如果想实现一个竖向滚动的列表,可以这样使用: ``` <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent"/> LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); recyclerView.setLayoutManager(layoutManager); ``` 如果想实现一个横向滚动的列表,可以这样使用: ``` <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent"/> LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); recyclerView.setLayoutManager(layoutManager); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值