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" />
相关推荐
qq_452396231 天前
第三篇:Transactional Outbox 模式详解
java·kubernetes·rocketmq
3095566661 天前
股票接口重试怎么分类:正常、空数组与错误响应的幂等处理
java·大数据·开发语言·数据库·php·api接口·股票数据api接口
booboosui1 天前
清单 40 件是硬上限:过期的活挂了 48 小时才被打标记
android
FlightYe1 天前
linux系统编程(二十一):C 语言常见坑
android·linux·运维·服务器·c语言·音视频
方白羽1 天前
SP vs DataStore:解锁 Android 本地存储的并发秘密
android·app·客户端
GY-931 天前
【Android】View和Componse
android
摇滚侠1 天前
《On Java 中文版 基础卷》阅读笔记 内部类 21
java·开发语言·笔记
王二蛋与他的张大花1 天前
后台内存 827MB,我一行业务逻辑都没改就砍到 100MB
android·flutter·性能优化
Paper_Love1 天前
android安全公告网站
android