0

ユーザーが友達に対して持っている「ゲーム」のリストをロードするAndroidゲームがあります。「友達とゲームの言葉」に似ている

このタイプのビューを再作成するために、私はもともとリストビューを使用していましたが、ゲーム、セクション (彼らの動き - あなたの動き) などのさまざまな要素があるため、純粋にリストビューでこの種のレイアウトを行うことはできないと思いますか?

誰かが似たようなことをしましたか?スクロール ビューを使用してレイアウトを動的に構築することもできますが、ユーザーが多くのゲームを持っている場合、パフォーマンスが低下するのではないかと心配しています。

誰でもアドバイスできますか?

4

1 に答える 1

1

getView()リストビュー アダプタでメソッドをオーバーライドする必要があります。各アイテムのレイアウトを表示する責任があります。そこで次のようなことができます:

if(position == YOUR_MOVE_POSITION) {

     // here hide ordinary elements, and set the ones you need to be visible
}

詳細については、こちらをご覧ください:リンク

例: (解決策の見方)

このメソッドはアダプタ クラスにあります ( ListView.

public View getView(int position, View convertView, ViewGroup parent) {

  final View v;

  if(position == 1) {  // here come instructions for 'header' no.1
    v = createViewFromResource(position, convertView, parent, mResource);

    // the widget you want to show in header:
    ImageView yourMoveImage = (ImageView) v.findViewById(R.id.your_move);

    // and here come widgets you don't want to show in headers:
    ImageView otherWidget = (ImageView) v.findViewById(R.id.other_widget);

    // then you set the visibility:
    yourMoveImage.setVisibility(View.VISIBLE);    // here is the key
    otherWidget.setVisibility(View.GONE);       // it may also be View.INVISIBLE (look up the official docs for details)   


  } else {

    if(position == 5){  // here come instructions for 'header' no.1


      v = createViewFromResource(position, convertView, parent, mResource);

      // the widget you want to show in header:
      ImageView theirMoveImage = (ImageView) v.findViewById(R.id.their_move);

      // and here come widgets you don't want to show in headers:
      ImageView otherWidget = (ImageView) v.findViewById(R.id.other_widget); 

      // then you set the visibility:
      yourMoveImage.setVisibility(View.VISIBLE);    // here is the key
      otherWidget.setVisibility(View.GONE);       // it may also be View.INVISIBLE (look up the official docs for details)   

    } else {

      // if it is the regular item, just show it as desribed in your XML:
      v = createViewFromResource(position, convertView, parent, mResource);
    }
  }

  return v;
}
于 2012-09-12T15:29:37.837 に答える