MuPDF Android Pdf 适合屏幕宽度和高度

在Android应用中使用Mupdf阅读PDF时,为了适应平板设备的横屏模式,需要修改ReaderView.class中的measureView方法以设置视图的缩放比例,确保PDF文件按屏幕宽度显示。代码主要关注宽度的适配,通过计算宽度比例并应用到MeasureSpec.EXACTLY中,从而实现横屏下的自适应布局。

在Android应用中有使用Mupdf进行PDF文件阅读,由于应用使用平板设备横屏使用,需要将文件默认显示为屏幕宽度大小,因此修改ReaderView.class中的measureView 缩放比例,代码如下:

    private void measureView(View v) {
        // See what size the view wants to be
        v.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);

        if (!mReflow) {
            // Work out a scale that will fit it to this view
            //高度适配横屏
//            float scale = Math.min((float) getWidth() / (float) v.getMeasuredWidth(),
//                    (float) getHeight() / (float) v.getMeasuredHeight());
            //宽度适配横屏
            float scale = (float)getWidth()/(float)v.getMeasuredWidth();
            v.measure(MeasureSpec.EXACTLY | (int) (v.getMeasuredWidth() * scale * mScale),
                    MeasureSpec.EXACTLY | (int) (v.getMeasuredHeight() * scale * mScale));
        } else {
            v.measure(MeasureSpec.EXACTLY | (int) (v.getMeasuredWidth()),
                    MeasureSpec.EXACTLY | (int) (v.getMeasuredHeight()));
        }
        requestLayout();
        post(this);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值