问题描述:

In my project i am rendering pdf, in landscape mode i am fitting to pagewidth and in portrait mode i am fitting to pageheight mode. can anybody suggest me how to do scrolling in landscape mode only and swiping in both orientations.

thank you in advance..

网友答案:

I would say the easiest way of doing this, assuming the scrolling is defines in your XML, is to create different layouts for each. somename_land.xml in the layout-land folder would have scrolling defined while somename_port.xml in layout-port would not. Both would have swiping. You then select the context in your code with something like this:

WindowManager winMan = (WindowManager) getBaseContext().getSystemService(Context.WINDOW_SERVICE);
if (winMan != null) {
    int orientation = winMan.getDefaultDisplay().getOrientation();

    if (orientation == 0) {
        // Portrait
        setContentView(R.layout.somename_port.xml);
    } else if (orientation == 1) {
        // Landscape
        setContentView(R.layout.somename_land.xml);
    }
}
相关阅读:
Top