Я создал пользовательский вид и добавил setOnClickListener ...
Странный диапазон касания вида
Как это исправить?
красный квадрат - это сенсорный диапазон ...
![enter image description here](https://i.stack.imgur.com/eb2ap.jpg)
![enter image description here](https://i.stack.imgur.com/qpTuz.jpg)
XML-файл (custom.xml)
<LinearLayout>
<TextView> ~~
<TextView> ~~
</LinearLayout>
JAVA-код (custom.java)
public class Custom_Lab_Button extends LinearLayout {
LinearLayout cus_lab_ll;
TextView cus_lab_tv1, cus_lab_tv2;
private void initView(Context context) {
inflate(getContext(), R.layout.custom_lab_button, this);
// String infService = Context.LAYOUT_INFLATER_SERVICE;
// LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(infService);
//// layoutInflater.inflate(R.layout.custom_lab_button, this, false);
// View v = layoutInflater.inflate(R.layout.custom_lab_button, getContent(), false);
// addView(v);
cus_lab_ll = (LinearLayout) findViewById(R.id.cus_lab_ll);
cus_lab_tv1 = (TextView) findViewById(R.id.cus_lab_tv1);
cus_lab_tv2 = (TextView) findViewById(R.id.cus_lab_tv2);
}
public void setCus_lab_ll_back(int cus_ll_resID) {
cus_lab_ll.setBackgroundColor(cus_ll_resID);
}
public void setCus_lab_ll_margin(LayoutParams layoutParams){
cus_lab_ll.setLayoutParams(layoutParams);
}
public LayoutParams getCus_lab_ll_margin(){
return (LayoutParams) cus_lab_ll.getLayoutParams();
}
}
Основной код Java
RelativeLayout cl_img = (RelativeLayout)view.findbyid(R.id.cl_img);
labButton = new Custom_Lab_Button(getActivity());
LinearLayout.LayoutParams tttt = labButton.getCus_lab_ll_margin();
tttt.leftMargin = 300;
tttt.topMargin = 300;
labButton.setCus_lab_ll_back(Color.BLUE);
labButton.setCus_lab_tv1_txt("lab1");
labButton.setCus_lab_ll_margin(tttt);
cl_img.addView(labButton);
labButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getContext(), "it is lab button 1/", Toast.LENGTH_SHORT).show();
}
});