0
有人能指導我一下,如何設計一個小部件的佈局如圖所示,附加的圖像佈局設計的部件
- 標有星號部分將成爲一個名人
- 的的縮略圖中對角線分隔符「/」的上方和下方部分應該有 單獨的聽衆。
有人能讓我以最好和有效的方式來設計這種佈局嗎?
任何幫助,非常感謝。
有人能指導我一下,如何設計一個小部件的佈局如圖所示,附加的圖像佈局設計的部件
有人能讓我以最好和有效的方式來設計這種佈局嗎?
任何幫助,非常感謝。
當然也有很多可能的解決方案。一個簡單的一種是:
對於您的自定義小部件,我建議從頭開始擴展現有的Android小部件而不是buildung。擴展一個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)
...
}
***要擴展的FrameLayout可能是一個很好的解決方案,因爲你可以有它由三角形疊加疊加一個recangular背景***不用java代碼來做這件事,我可以在xml中定義它並在java代碼中使用它嗎? – user264953
請告訴我更多你想要達到的行爲。當然,可以設計XML中的everthing並在代碼中引用它。例如在上面的例子中,我沒有進一步指定方法createFirstView(),createSecondView()。在這些方法中,你當然可以用XML來擴充具體的佈局。如果用戶只需點擊左上角或右下角的部分,就可以使用XML設計所有內容,並且只需將onTouchListener分配給點擊事件的區別即可。所以請告訴我更多,我會更新我的答案:-) – a11n