我怎么知道我自己认为设备方向已经改变了?

时间:2012-04-25 05:58:47

标签: android events view device-orientation measure

我扩展了ViewFlipper小部件。当我初始化MyViewFlipper时,我将List oa对象传递给它。 MyViewFlipper执行它列表并向MyViewFlipper添加一些视图。

我的活动有android:configChanges =“keyboardHidden | orientation”,因此,当设备方向改变时,我的视图不会重新创建。

我必须在我的MyViewFlipper中覆盖哪个方法来处理方向更改事件以在MyViewFlipper中重新创建我的子视图?

如何做别人的观点?

Methid,在MyViewFlipper中执行对象列表:

public void setUsers(List<User> users)
{
    removeAllViews();

    Display display = ((WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int maxWidth = display.getWidth();

    screens = new LinearLayout[maxScreens];
    int fillingScreen = maxScreens;

    while(fillingScreen > 0) 
    {
        LinearLayout linearLayout = new LinearLayout(getContext());
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
        linearLayout.setGravity(Gravity.CENTER);
        screens[fillingScreen - 1] = linearLayout;
        fillingScreen --;
    }

    int currentUser = 0;

    while(currentUser < users.size() && fillingScreen < maxScreens)
    {

        LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.item_people_category_item, null);
        ImageView iv = (ImageView) linearLayout.findViewById(R.id.item_people_category_item_avatar);

        screens[fillingScreen].addView(linearLayout);
        screens[fillingScreen].measure(0, 0);

        if (screens[fillingScreen].getMeasuredWidth() >= maxWidth)
        {
            screens[fillingScreen].removeView(linearLayout);
            addView(screens[fillingScreen]);
            fillingScreen ++;
        }
        else 
        {
            User user = users.get(currentUser);
            iv.setOnClickListener(ouUserClicked);
            linearLayout.setTag(user);
            App._IMAGEMANAGER.setImage(user.getPhoto(), iv, R.drawable.no_photo);
            currentUser++;
        }
    }

    if (fillingScreen < maxScreens && screens[fillingScreen].getParent() == null) addView(screens[fillingScreen]);
}

它简单地将一些LinwarLayout添加到ViewFlipper中,并使用muximim可能的对象数量。

PS:

   @Override
    public void onConfigurationChange(Configuration newConf) {
      // notify view flopper here
    }

我的布局中的其他视图无需通知。他们改变了表征自我。他们使用的方法是什么? onMeauser()?

2 个答案:

答案 0 :(得分:1)

你应该覆盖

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

这可以检测方向变化......

答案 1 :(得分:0)

不是观点的方法,坚果的活动方法:

@Override
public void onConfigurationChange(Configuration newConf) {
  // notify view flopper here
}
相关问题