I have a ViewGroup
and I'm adding child Views to i开发者_如何学Got 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?
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.
精彩评论