0

ViewFlipper ウィジェットを拡張します。MyViewFlipper を初期化するときに、List オブジェクトをそれに渡します。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()?

4

2 に答える 2

1

オーバーライドする必要があります

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

これは向きの変化を検出するために...

于 2012-04-25T06:03:14.357 に答える
0

それは見方の​​方法ではなく、活動のナッツの方法です。

@Override
public void onConfigurationChange(Configuration newConf) {
  // notify view flopper here
}
于 2012-04-25T06:03:07.943 に答える