首页 > 解决方案 > PDFTron 中的 CustomRelativeLayout Layout_with 和 layout_height 不起作用

问题描述

嗨,我在 Android Xamarin 项目的 PDFViewerCtrl 中有这个 CustomRelativeLayout:

  <pdftron.PDF.Tools.CustomRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="250dp"
    android:layout_height="250dp"
    app:posX="50"
    app:posY="150"    
    app:pageNum="1"
    android:background="#33AFAFFF"
    app:zoomWithParent="true">
    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_red_dark" />
</pdftron.PDF.Tools.CustomRelativeLayout>

当它被渲染时,我看到了:在此处输入图像描述

位置 x=50 y=150 的 50*150 矩形。但我希望在页面位置 x=50 y=150 处绘制一个 250x250 的矩形。有什么我没有考虑或我做错了吗?我想扩展 RelativeLayout 以理想地匹配父 PDFPage。

谢谢。

标签: xamarin.androidpdftronpdfnet

解决方案


您可以将布局更新为

<pdftron.PDF.Tools.CustomRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="250dp"
    android:layout_height="250dp"
    android:id="@+id/container"
    app:posX="50"
    app:posY="150"    
    app:pageNum="1"
    android:background="#33AFAFFF"
    app:zoomWithParent="true">
    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_red_dark" />
</pdftron.PDF.Tools.CustomRelativeLayout>

然后,更新代码:

private void _pdfControl_DocumentLoad(object sender, System.EventArgs e)
{
        var note = LayoutInflater.Inflate(Resource.Layout.pdf_custom_layout, _pdfControl);
        var layout = note.FindViewById<CustomRelativeLayout>(Resource.Id.container);
        layout.SetRect(_pdfControl, new pdftronprivate.PDF.Rect(50, 50, 300, 300), 1);
}

注意必须在页面坐标中指定所有点。

你会看见:

在此处输入图像描述


推荐阅读