我成功地爲我的Android應用安裝了MuPDF。但問題是,在渲染時,我無法使PDF適合屏幕。任何人都可以請建議我如何實現這一點。謝謝!MuPDF Android Pdf適合屏幕
4
A
回答
4
編輯ReaderView.java中的measureView方法變成。
private void measureView(View v) {
// See what size the view wants to be
v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
// Work out a scale that will fit it to this view
float scale;
if (getWidth()>getHeight())
{
scale = (float)getWidth()/(float)v.getMeasuredWidth();
MIN_SCALE = (float)v.getMeasuredWidth()/(float)getWidth();
MAX_SCALE = MIN_SCALE*5.0f;
}
else
scale = Math.min((float)getWidth()/(float)v.getMeasuredWidth(),
(float)getHeight()/(float)v.getMeasuredHeight());
// Use the fitting values scaled by our current scale factor
v.measure(View.MeasureSpec.EXACTLY | (int)(v.getMeasuredWidth()*scale*mScale),
View.MeasureSpec.EXACTLY | (int)(v.getMeasuredHeight()*scale*mScale));
}
0
與此頁面調整大小從視圖啓動太大。這裏是「measureview」法在我的代碼:
private void measureView(View v) {
// See what size the view wants to be
v.measure(View.MeasureSpec.UNSPECIFIED, View.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());
// Use the fitting values scaled by our current scale factor
v.measure(MeasureSpec.AT_MOST | (int) (v.getMeasuredWidth() * (scale + 0.8f) * mScale),
MeasureSpec.AT_MOST | (int) (v.getMeasuredHeight() * (scale+0.8f) * mScale));
} else {
v.measure(View.MeasureSpec.EXACTLY | (int) (v.getMeasuredWidth()),
View.MeasureSpec.EXACTLY | (int) (v.getMeasuredHeight()));
}
}
這是我需要的,啓動頁面需要以完全相同的觀點,開機要獲取與文本的可讀性。
-1
除了回答https://stackoverflow.com/a/21168243/2982225, 您可以通過在結尾處添加以下代碼重新渲染視圖:
requestLayout();
post(this);
一次。
所以完整的代碼如下(歸屬代碼最後的評論之前:the accepted answer of this question):
private void measureView(View v) {
// See what size the view wants to be
v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
// Work out a scale that will fit it to this view
float scale;
if (getWidth()>getHeight())
{
scale = (float)getWidth()/(float)v.getMeasuredWidth();
MIN_SCALE = (float)v.getMeasuredWidth()/(float)getWidth();
MAX_SCALE = MIN_SCALE*5.0f;
}
else
scale = Math.min((float)getWidth()/(float)v.getMeasuredWidth(),
(float)getHeight()/(float)v.getMeasuredHeight());
// Use the fitting values scaled by our current scale factor
v.measure(View.MeasureSpec.EXACTLY | (int)(v.getMeasuredWidth()*scale*mScale),
View.MeasureSpec.EXACTLY | (int)(v.getMeasuredHeight()*scale*mScale));
// last comment
// to force the initial rendering to the new scale
requestLayout();
post(this);
}
希望這有助於。
0
我對MAX和MIN的最終變量有錯誤,但是我對@ hassan83的解決方案做了一些修改。我的解決辦法是在MuPDF版本測試1.9A
private void measureView(View v) {
// See what size the view wants to be
v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
// Work out a scale that will fit it to this view
float scale;
//landscape orientation
if (getWidth() > getHeight())
{
scale = (float)getWidth()/(float)v.getMeasuredWidth() * (1.0f); //make sure that we fill the page by multiplying with a scale factor of one
}
else
scale = Math.min((float)getWidth()/(float)v.getMeasuredWidth(),
(float)getHeight()/(float)v.getMeasuredHeight());
// Use the fitting values scaled by our current scale factor
v.measure(View.MeasureSpec.EXACTLY | (int)(v.getMeasuredWidth()*scale*mScale),
View.MeasureSpec.EXACTLY | (int)(v.getMeasuredHeight()*scale*mScale));
}
相關問題
- 1. 視窗Android適合屏幕
- 2. 適合屏幕
- 3. android gridview適合屏幕大小
- 4. Android的cocos2d適合精靈屏幕
- 5. Android中的Webview圖像適合屏幕
- 6. Android,如何使圖像適合屏幕?
- 7. 使圖像適合Android屏幕
- 8. android表格佈局不適合屏幕
- 9. Android Gallery圖像onTouch以適合屏幕
- 10. Android ListView:項目適合屏幕
- 11. Android屏幕上適合recyclerview項目
- 12. Android ImageView不適合較大的屏幕
- 13. 適合所有屏幕的Android設計
- 14. Android佈局不適合屏幕
- 15. 佈局不適合屏幕
- 16. Bootstrap Modal不適合屏幕
- 17. 適合更大屏幕尺寸的Android伸縮屏幕
- 18. Cardview不適合屏幕
- 19. 適合頁面內容適合iphone,android屏幕與javascript
- 20. 使圖像適合屏幕
- 21. Bootstrap組件適合屏幕
- 22. 使HTML Canvas適合屏幕
- 23. 適合網頁到屏幕
- 24. UIImageView適合整個屏幕
- 25. 圖像不適合屏幕
- 26. 的Iframe適合屏幕
- 27. Xcode UILabel適合屏幕
- 28. Smartgit Ubuntu不適合屏幕
- 29. 手機間隙屏幕圖像不適合屏幕
- 30. 如何使pdf頁面適合屏幕尺寸在讀卡器
同樣的問題我.. –