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" />
相关推荐
程序员黑豆2 小时前
Java包装类:基本类型与对象的桥梁
java·前端·ai编程
牛哇网络工作室4 小时前
UnityHDRP写实数字人全流程基础5—语音输入和语音识别
android·unity·c#·游戏引擎·aigc·语音识别·xcode
一笑的小酒馆5 小时前
Androidiot蓝牙配网简单封装
android
mldong5 小时前
"applicant" 契约:退回发起人的闭环设计
java·架构
月华路6 小时前
G1 垃圾回收:脏卡队列、记忆集与并发精化线程机制
java·开发语言
gugucoding6 小时前
47. 【Java】Java内存模型(JMM)与可见性
java·开发语言
zww89491117 小时前
校园跑腿系统开发实战指南:从需求分析到上线部署全流程解析
java
Fluxart.ai7 小时前
电商商品图审核怎么自动化?规则引擎、人工复核与发布门禁
java·前端·自动化
愚公搬代码7 小时前
【愚公系列】《Android应用案例开发大全》016-LBS类应用掌上杭州(辅助工具类的开发)
android·前端
名字还没想好☜8 小时前
Java 线上内存泄漏排查实战:jmap 导堆、MAT 找 GC Roots 与四类常见泄漏
java·开发语言·jvm·内存泄漏