커스텀 xml 파일을 작성하여
자바 코드상에서 생성하고 배치, 레이아웃 제어를 하고싶습니다.
inflate를 사용하여 생성을 했는데 터치 이벤트가 안먹히거나 레이아웃배치가 안되네요...
어떻게 해야할까요?
 요렇게 TextView를 개별적인 xml파일로 생성하여 사용하고있습니다.
 요렇게 TextView를 개별적인 xml파일로 생성하여 사용하고있습니다.
 
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(getContext().LAYOUT_INFLATER_SERVICE);
View vg = (View) inflater.inflate(R.layout.custom_lab_button, cl_img, true);
//ConstraintLayout.LayoutParams tt = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.WRAP_CONTENT);
ConstraintLayout.LayoutParams tt = (ConstraintLayout.LayoutParams) vg.getLayoutParams();
//cl_img.addView(vg);
Log.d("qqq", "margin1: " + String.valueOf(((RelativeLayout.LayoutParams) vg.getLayoutParams()).topMargin));
tt.setMargins(100, 100, 0, 0);
vg.setLayoutParams(tt);inflater를 생성하고 cl_img(ConstraintLayout)를 root로 했는데, LayoutParams를 ConstraintLayout으로 잡으면 에러가나고 Relative로 잡아야 동작을합니다.(Relative는 cl_img의 root레이아웃)
cl_img안에서 vg(뷰)의 레이아웃을 조절하고 싶습니다.