我有以下情况:
这是可行的,但也许这是一个hack(请参见下面的代码)
我想做什么:
单击主Customview时,无法更改Web视图的位置和大小。
代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
ConstraintLayout constraintLayout = new ConstraintLayout(this);
MainCustomView mainCustomView = new MainCustomView(this);
mainCustomView.setId(View.generateViewId());
constraintLayout.addView(mainCustomView);
mainCustomView.setLayoutParams(new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT));
final SubCustomView subCustomView = new SubCustomView(this);
subCustomView.setLayoutParams(new ViewGroup.LayoutParams(BOX_WIDTH, BOX_HEIGHT));
subCustomView.setId(View.generateViewId());
constraintLayout.addView(subCustomView);
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.connect(subCustomView.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP, BOX_TOPMARGIN);
constraintSet.connect(subCustomView.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT, BOX_LEFTMARGIN);
constraintLayout.setConstraintSet(constraintSet);
subCustomView.loadData(getBeforeClickText(), "text/html", "UTF-8");
mainCustomView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
subCustomView.loadData(getAfterClickText(), "text/html", "UTF-8");
<<<<<<<<<<< New POSITION and SIZE of the Webview >>>>>>>>>>>
}
});
setContentView(constraintLayout);
}
问题: 我怎样才能做到这一点 ?是我以正确的方式开始的方法,还是在动态显示和更改Webview以及与其交互时是否有更好的解决方案?也许使用ViewOverlay?