Android的RealViewSwitcher显示视图部分 [英] Android RealViewSwitcher shows view partially

查看:336
本文介绍了Android的RealViewSwitcher显示视图部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题。我使用RealViewSwitcher类(它扩展的ViewGroup,可以成立的此处)。我有三个视图以及它们之间的刷卡两个orientatons效果很好。然而,当我动态地改变方向(例如,我在纵向视图的画面1上改变方向为水平方向) - 该视图只显示部分(屏幕的三分之一是第一种观点,另外两个三分之一 - 第二视图)。

I've got the following problem. I'm using the RealViewSwitcher class (which extends ViewGroup and can be founded here ). I've got three views and swiping between them works well in both orientatons. However, when I change orientation dynamically (for example, I'm on the screen 1 in vertical view and change the orientation to horizontal) - the view is showing only partially (one third of the screen is first view, other two third - second view).

在code:

// my activity method
@Override
public void onConfigurationChanged(Configuration newConfig)
{
// ...
realViewSwitcher.setCurrentScreen(1);
// ...
}

// realViewSwitcher method
public void setCurrentScreen(int currentScreen) {
    mCurrentScreen = Math.max(0, Math.min(currentScreen, getChildCount() - 1));
    scrollTo(mCurrentScreen * getWidth(), 0);
    invalidate();
}

UPD(2012年9月10日):增加了一些code

UPD(10.09.2012): Added some code

推荐答案

下面的代码片断添加到您的RealViewSwitcher类,

Add the following snippet to your RealViewSwitcher Class,

public void orientationSnapToScreen(Context ctx)
        {
            Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
            int displayWidth = display.getWidth();

            mNextScreen = Math.max(0, Math.min(getCurrentScreen(), getChildCount() - 1));
            final int newX = mNextScreen * displayWidth;
            final int delta = newX - getScrollX();

            mScroller.startScroll(getScrollX(), 0, delta, 0, 0);
        }

和从添加下面的方法到您的主要活动,你所呼叫的RealViewSwitcher类

and add the following method to your main activity from where you are calling the RealViewSwitcher class

@Override
    public void onConfigurationChanged(Configuration newConfig) 
    {
        super.onConfigurationChanged(newConfig);
        realViewSwitcher.orientationSnapToScreen(this);
    }

这篇关于Android的RealViewSwitcher显示视图部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆