我扩展了ViewFlipper小部件。当我初始化MyViewFlipper时,我将List对象传递给它。 MyViewFlipper执行它的列表并添加一些视图到MyViewFlipper。如何在我的视图中知道设备方向已更改?
我的活动有android:configChanges =“keyboardHidden | orientation”,因此我的视图hiererchy在设备方向改变时不能重新创建。
在我的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]);
}
它simpe添加一些LinwarLayout使用对象的muximim possiable数量ViewFlipper。
PS:
@Override
public void onConfigurationChange(Configuration newConf) {
// notify view flopper here
}
在我的布局其他的观点并不需要通知。他们改变表征自我。他们使用什么方法? onMeauser()?
您应该调用onDraw方法...来绘制您的视图... – 5hssba 2012-04-25 06:15:18
您仍面临同样的问题? – 5hssba 2012-04-26 11:13:29