添付の画像に示すように、ウィジェットのレイアウトを設計する方法について誰かが私を案内してくれますか
- スター付きの部分は有名人のサムネイル画像になります
- 斜めの仕切り「/」の上と下の部分には、別々のリスナーが必要です。
このレイアウトを設計するための最良かつ効率的な方法を教えてください。
どんな助けでも大歓迎です。
添付の画像に示すように、ウィジェットのレイアウトを設計する方法について誰かが私を案内してくれますか
このレイアウトを設計するための最良かつ効率的な方法を教えてください。
どんな助けでも大歓迎です。
もちろん、可能な解決策はたくさんあります。簡単なものは次のとおりです。
カスタム ウィジェットについては、ゼロから構築するのではなく、既存の 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)
...
}