Android 开发问题:为 PDFView 设置一个带有黑色边框的背景 drawable,但边框没有生效

xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <stroke
        android:width="1dp"
        android:color="@color/black" />
</shape>
xml 复制代码
<com.github.barteksc.pdfviewer.PDFView
    android:id="@+id/pdfv_container"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_marginTop="20dp"
    android:background="@drawable/item_dialog_notice_pdfv_container" />
  • 在 Android 开发中,执行上述代码,为 PDFView 设置一个带有黑色边框的背景 drawable,但边框没有生效
问题原因
  • PDFView 在绘制 PDF 页面时会覆盖掉背景 drawable 的绘制
处理策略
  • 用一个外层容器包裹 PDFView,把边框加在外层容器上,同时给外层容器设置内边距
xml 复制代码
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_marginTop="20dp"
    android:background="@drawable/item_dialog_notice_pdfv_container"
    android:padding="1dp">

    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfv_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>
  • 也尝试过给 PDFView 设置内边距,让 PDF 内容不贴边,但是这种方法无效
xml 复制代码
<com.github.barteksc.pdfviewer.PDFView
    android:id="@+id/pdfv_container"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_marginTop="20dp"
    android:background="@drawable/item_dialog_notice_pdfv_container"
    android:padding="1dp" />
相关推荐
好的佩奇3 小时前
Dart 之扩展方法
android·flutter·dart
这个昵称不容易3 小时前
SpringBoot「衣依」服装销售平台:144个Java文件180个接口,从挑衣服到收货评价整条链路都在
java·springboot·毕设
计算机毕设定制辅导-无忧学长4 小时前
《基于微信小程序的居家医疗陪护预约系统设计与实现》
java·spring boot·微信小程序·uniapp·居家医疗陪护预约系统
三少爷的鞋4 小时前
换个思路理解:非阻塞挂起
android
文丑颜不良啊5 小时前
LeetCode2221~2240题目解析
java·leetcode
秋饼5 小时前
Computer Use Agent Java 落地实战:感知-行动循环、执行器与安全围栏生产级实现
java·ai·技术分享·后端开发
好的佩奇5 小时前
蓝牙之经典蓝牙
android·flutter·蓝牙
文丑颜不良啊7 小时前
LeetCode2161~2180题目解析
java·leetcode
传奇开心果编程8 小时前
【Flutter踩坑排雷】第19课:路由硬编码坑|字符串路由书写错误,页面跳转失败排查
android·flutter·ios·移动开发·跨平台·ui框架·声明式ui
文丑颜不良啊9 小时前
LeetCode2141~2160题目解析
java·leetcode