<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><strokeandroid:width="1dp"android:color="@color/black"/></shape><com.github.barteksc.pdfviewer.PDFViewandroid: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,把边框加在外层容器上,同时给外层容器设置内边距
<FrameLayoutandroid: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.PDFViewandroid:id="@+id/pdfv_container"android:layout_width="match_parent"android:layout_height="match_parent"/></FrameLayout>- 也尝试过给 PDFView 设置内边距,让 PDF 内容不贴边,但是这种方法无效
<com.github.barteksc.pdfviewer.PDFViewandroid: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"/>