0

添付の画像に示すように、ウィジェットのレイアウトを設計する方法について誰かが私を案内してくれますか

  1. スター付きの部分は有名人のサムネイル画像になります
  2. 斜めの仕切り「/」の上と下の部分には、別々のリスナーが必要です。

このレイアウトを設計するための最良かつ効率的な方法を教えてください。

どんな助けでも大歓迎です。

ここに画像の説明を入力

4

1 に答える 1

1

もちろん、可能な解決策はたくさんあります。簡単なものは次のとおりです。

  • 標準の ListView を利用する
  • カスタム アダプター (この目的のために BaseAdapter を拡張) で各行を埋める
  • リスト項目のレイアウトは、水平方向の LinearLayout を使用する必要があります
  • 「/」区切り専用のカスタム ウィジェットを作成する
  • リスト項目のレイアウトに ImageView (有名人の写真用) を配置し、必要なカスタム "/" ウィジェットのメニューとして追加します

カスタム ウィジェットについては、ゼロから構築するのではなく、既存の Android ウィジェットを拡張することをお勧めします。三角形のオーバーレイでオーバーレイされた長方形の背景を持つことができるため、 FrameLayout を拡張することは良い解決策かもしれません。onTouchListener を使用すると、どれがクリックされたかを検出できます。

このようにして、このようなウィジェットを作成する労力は、可能な限り多くの標準ソリューションを使用することで最小限に抑えられます。

カスタム ウィジェットの抽象的な実装例を次に示します。

    public class DividedView extends FrameLayout implements OnTouchListener {
          public void onCreate(Context context, AttributeSet attr){
              View firstView =  createFirstView();

              View secondView = createSecondView(); //this view has a triangle shape but with a transparent buttom-right corner... but the boundaries match the complete size of this custom widget... therefore this view consumes all touch events
              secondView.setOnTouchListener(this);

              addView(firstView);
              addView(secondView);
          }

          ...

          public boolean onTouch(MotionEvent event){
              switch(event.getAction(){
                   case MotionEvent.ACTION_DOWN:
                    //detect if coordinates of touch down are in boundaries of first or second view... if yes trigger click event for firstView or secondView depending on coordinates
                    break;
              }
          }

          //via this method you can set corresponding click listener for each of the divided views
          public void setFirstViewOnClickListener(OnClickListener onClickListener)
          ...

    }
于 2013-07-17T11:58:39.200 に答える