一.使用TouchDelegate增加控件可點(diǎn)擊區(qū)域
TouchDelegate API
TouchDelegate Demo
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the parent view
View parentView = findViewById(R.id.parent_layout);
parentView.post(new Runnable() {
// Post in the parent's message queue to make sure the parent
// lays out its children before you call getHitRect()
@Override
public void run() {
// The bounds for the delegate view (an ImageButton
// in this example)
Rect delegateArea = new Rect();
ImageButton myButton = (ImageButton) findViewById(R.id.button);
myButton.setEnabled(true);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,
"Touch occurred within ImageButton touch region.",
Toast.LENGTH_SHORT).show();
}
});
// 獲取子視圖初始時(shí)的區(qū)域
myButton.getHitRect(delegateArea);
delegateArea.right += 100;
delegateArea.bottom += 100;
增加后的區(qū)域 ,子控件
TouchDelegate touchDelegate = new TouchDelegate(delegateArea,myButton);
if (View.class.isInstance(myButton.getParent())) {
((View) myButton.getParent()).setTouchDelegate(touchDelegate);///父容器設(shè)置代理
}
}
});
}
}
二.使用Padding
增加padding語氣變大