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 小时前
深入理解 Kotlin 协程 (八):拾遗补阙,探秘官方框架的调度细节与取消闭环
android·kotlin
都叫我大帅哥3 小时前
从Python到Java:为什么企业级Agent最终会选择Java?
java·ai编程
wanderist.3 小时前
Lambda表达式在算法竞赛中的应用
java·开发语言·算法
海天鹰4 小时前
PHP上传文件
android·开发语言·php
腻害兔5 小时前
【若依项目-产品经理视角】RuoYi-Vue-Pro 源码拆解:IM 即时通讯模块,一个被低估的「全功能聊天系统」
java·前端·vue.js·产品经理·ai编程
心念枕惊5 小时前
.NET CORE 授权进阶-角色、策略与动态权限实现
java·前端·.netcore
2501_915918416 小时前
详解iOS App上架至App Store的全流程步骤与注意事项
android·macos·ios·小程序·uni-app·cocoa·iphone
景同学7 小时前
把 AI 用到线上运维:可行、有效,前提是喂足信息——一次 Full GC 排障实录
java·人工智能·后端
码农coding7 小时前
android12 SystemUI之StatusBar(二)
android