让 FrameLayout 展开,它的子元素也展开
如何动态更改 FrameLayout 的大小并且它的子级也得到扩展?
编辑:到目前为止,我得到了这个但不起作用:
public class ResizableArea extends FrameLayout {
private View child;
public ResizableArea(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() > 1){
Vector2D p1 = new Vector2D(event.getX(0), event.getY(0));
Vector2D p2 = new Vector2D(event.getX(1), event.getY(1));
float dist = p1.minus(p2).getSize();
resizeChildBy(dist);
}
return true;
}
private void resizeChildBy(float size) {
LayoutParams params = (LayoutParams) child.getLayoutParams();
params.height -= size;
params.width -= size;
child.setLayoutParams(params);
invalidate();
}
@Override
public void addView(View child) {
if (getChildCount() != 0)
throw new IllegalStateException("ResizableArea can only have one child attached!");
this.child = child;
super.addView(child);
}
}
How can I change the size of a FrameLayout dynamically and it's childs get expanded too?
EDIT: So far, I got this but doesn't work:
public class ResizableArea extends FrameLayout {
private View child;
public ResizableArea(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() > 1){
Vector2D p1 = new Vector2D(event.getX(0), event.getY(0));
Vector2D p2 = new Vector2D(event.getX(1), event.getY(1));
float dist = p1.minus(p2).getSize();
resizeChildBy(dist);
}
return true;
}
private void resizeChildBy(float size) {
LayoutParams params = (LayoutParams) child.getLayoutParams();
params.height -= size;
params.width -= size;
child.setLayoutParams(params);
invalidate();
}
@Override
public void addView(View child) {
if (getChildCount() != 0)
throw new IllegalStateException("ResizableArea can only have one child attached!");
this.child = child;
super.addView(child);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,这是正确的答案:
Actually, this is the right answer: