Child Views that are translated, scaled or rotated disappear

∥☆過路亽.° 提交于 2020-01-15 03:36:09

问题


I have a ViewGroup and I'm adding child Views to it like this:

mViewGroup.addView(view, new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));

(the WRAP_CONTENT is important for the onclicklistener to work as expected).

So far so good, but later I move the child Views around dynamically by either overriding their onDraw methods or by overriding the ViewGroups:

protected boolean getChildStaticTransformation(View child, Transformation t)

The problem is that the Children disappear if they are moved outside their original region which seems to be calculated when they are first added. I tried calling setClipChildren(false); but it didn't work.

I could solve the problem by using LayoutParams.FILL_PARENT when adding the child views but in this case the onClickListener would react to any click on the whole ViewGroup and I want it to only react to clicks on the specific area where my transformed child View is located.

Maybe I could still use LayoutParams.FILL_PARENT if there is a way to define where the clickable region for the View should be.

Any suggestions?


回答1:


Perhaps you should experiment with margins and paddings of your child views. Otherwise you could try to use a different ViewGroup layout like a FrameLayout where the postion of each view can be set by its margins.



来源:https://stackoverflow.com/questions/4973606/child-views-that-are-translated-scaled-or-rotated-disappear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!