将EditText居中放在一条线的中点

时间:2017-03-04 14:23:48

标签: android android-layout

我目前正在开发Android平面图应用。到目前为止,可以在画布上绘制直线连接线,其中端点是下一行的起点。所有行都存储在带有xstart,ystart,xend和yend变量的ArrayList中。在我的下一步中,我想在每行的中点放置EditText字段。不幸的是我的代码不起作用。这是我尝试的方式:

    for (int i=0; i<wallList.size(); i++) {
         double xs=wallList.get(i).getXstart();
         double ys=wallList.get(i).getYstart();
         double xe=wallList.get(i).getXend();
         double ye=wallList.get(i).getYend();
         length= sqrt(Math.pow((xs-xe),2)+Math.pow((ys-ye),2));
         Log.e(TAG, "length: " + String.valueOf(length));
         x_midpoint=(xs+xe)/2;
         y_midpoint=(ys+ye)/2;
         createTextView(length, x_midpoint, y_midpoint);
                    }    

    private void createTextView(double number, double x_midpoint, double y_midpoint){
        EditText text = new EditText(this);
        text.setPadding ((int)y_midpoint, (int)x_midpoint, 0, 0);
        text.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
        text.setText(String.valueOf(Math.round(number)), TextView.BufferType.EDITABLE);
        rl.addView(text);
    }    

How it is shown

任何人都可以帮助我吗?

0 个答案:

没有答案
相关问题