我扩展了 ViewFlipper 小部件。当我初始化 MyViewFlipper 时,我将 List oа 对象传递给它。MyViewFlipper 执行它列表并将一些视图添加到 MyViewFlipper。
我的活动有 android:configChanges="keyboardHidden|orientation",因此当设备方向改变时我的视图层次结构不会重新创建。
我必须在 MyViewFlipper 中重写哪种方法来处理方向更改事件以在 MyViewFlipper 中重新创建我的子视图?
别人的看法怎么办?
在 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 中,并具有尽可能多的对象数量。
PS:
@Override
public void onConfigurationChange(Configuration newConf) {
// notify view flopper here
}
我的布局中的其他视图不需要通知。他们改变代表自我。他们使用哪种方法?onMeauser()?