Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我怎样才能这样定位我的观点?网上购物_Java_Android_Android Viewgroup - Fatal编程技术网

Java 我怎样才能这样定位我的观点?网上购物

Java 我怎样才能这样定位我的观点?网上购物,java,android,android-viewgroup,Java,Android,Android Viewgroup,我试图定位我的观点(只是点模式),就像在这张照片没有成功。 有人能帮我弄清楚我应该如何使用onLayout吗? 谢谢 @覆盖 仅限受保护的空心布局(布尔值已更改、整数左侧、整数顶部、整数右侧、整数底部){ 最终整数计数=getChildCount(); int curWidth、curHeight、curLeft、curTop、maxHeight; //获取子视图的可用大小 int childLeft=this.getPaddingLeft(); int childTop=this.getPad

我试图定位我的观点(只是点模式),就像在这张照片没有成功。 有人能帮我弄清楚我应该如何使用onLayout吗? 谢谢

@覆盖
仅限受保护的空心布局(布尔值已更改、整数左侧、整数顶部、整数右侧、整数底部){
最终整数计数=getChildCount();
int curWidth、curHeight、curLeft、curTop、maxHeight;
//获取子视图的可用大小
int childLeft=this.getPaddingLeft();
int childTop=this.getPaddingTop();
int childRight=(int)getResources().getDimension(R.dimen.circle_width)-this.getPaddingRight();
int childBottom=(int)getResources().getdimen(R.dimen.circle_width)-this.getPaddingBottom();
int childWidth=childRight-childLeft;
int childHeight=childBottom-childTop;
最大高度=0;
curLeft=childLeft;
curTop=儿童托普;
//遍历每个孩子,从左到右排列
for(int i=0;i=childRight){
curLeft=childLeft;
curTop+=最大高度;
最大高度=0;
}
//做布局
布局(curLeft、curTop、curLeft+curWidth、curTop+curHeight);
//存储最大高度
if(最大高度<当前高度)
maxHeight=curHeight;
curLeft+=curWidth;
}
}
}

首先,你不应该在
onLayout
中这样做,它会被多次调用,你可能不需要这样做。为什么不在
构造函数内部准备
呢,或者如果点只在
onDraw
内部绘制,将比只使用简单位图添加大量
视图更有效。可能会在屏幕上显示您所拥有的,是否应该有动画?

其实很容易,您可以在XML布局中构建它。在最简单的表示法中,它只是三个相互垂直位移的点视图。定义垂直方向的线性布局(权重总和=3),布局三个视图(权重=1)。然后使用布局边距相对移动每个视图。对于这样的场景,一个完美的布局应该是更灵活的约束布局


这是一个结合自定义手势处理的很好的教程,

也不要在onLayout中执行图形化操作,请尝试构造函数。我可以在XML布局上实现模式锁定吗?我需要批准使用此模式的操作。您的意思是完全按照布局,如果是,那么当然可以。您可以通过在屏幕上启用手势来为其添加超级功能简单的滑动手势,如模式布局应该是一个模式锁。我只需要画出这3个点,并在它们之间连接,当我想批准我的行动,如在这张照片。照片实际上是我制作图案后想要的结果。你想要一个没有与
MotionEvent
s交互的静态图像还是通过其他点动画/交互的整个绘制线?它应该像锁图案一样工作。当我按下图像的颜色应该是白色(我改变了可绘制的),并画一条V型线,以批准我的行动。我希望用户能够仅在点之间绘制线。因此,您必须根据
MotionEvent
s位置覆盖并使用覆盖的
onDraw
方法。这是一个更大的案例,需要一段可靠的代码才能工作。当然,
onLayout
不是放置图形代码的最佳位置
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final int count = getChildCount();
    int curWidth, curHeight, curLeft, curTop, maxHeight;

    //get the available size of child view
    int childLeft = this.getPaddingLeft();
    int childTop = this.getPaddingTop();
    int childRight = (int) getResources().getDimension(R.dimen.circle_width) - this.getPaddingRight();
    int childBottom = (int) getResources().getDimension(R.dimen.circle_width) - this.getPaddingBottom();
    int childWidth = childRight - childLeft;
    int childHeight = childBottom - childTop;

    maxHeight = 0;
    curLeft = childLeft;
    curTop = childTop;
    //walk through each child, and arrange it from left to right
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            //Get the maximum size of the child
            child.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.AT_MOST),
                    MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.AT_MOST));
            curWidth = child.getMeasuredWidth();
            curHeight = child.getMeasuredHeight();

            //wrap is reach to the end
            if (curLeft + curWidth >= childRight) {
                curLeft = childLeft;
                curTop += maxHeight;
                maxHeight = 0;
            }

            //do the layout
            child.layout(curLeft, curTop, curLeft + curWidth, curTop + curHeight);

            //store the max height
            if (maxHeight < curHeight)
                maxHeight = curHeight;
            curLeft += curWidth;
        }
    }
}