Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.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
Android 将EditView覆盖在自定义视图的顶部_Android_Android Layout - Fatal编程技术网

Android 将EditView覆盖在自定义视图的顶部

Android 将EditView覆盖在自定义视图的顶部,android,android-layout,Android,Android Layout,我尝试用EditView覆盖我的自定义视图,取得了不同程度的成功 解决方案需要结合这样一个事实,即我的自定义视图执行绘制画布时执行的各种计算。计算,如计算中心X和Y坐标、画布尺寸等 这些计算将用于在屏幕上定位EditText 到目前为止,我已经明白了一个RelativeLayout是覆盖的方式 到目前为止,最好的解决方案(并不理想)是创建一个自定义的RelativeLayout,如下所示: public class MyCustomRL extends RelativeLayout {

我尝试用
EditView
覆盖我的自定义视图,取得了不同程度的成功

解决方案需要结合这样一个事实,即我的自定义视图执行绘制画布时执行的各种计算。计算,如计算中心X和Y坐标、画布尺寸等

这些计算将用于在屏幕上定位
EditText

到目前为止,我已经明白了一个
RelativeLayout
是覆盖的方式

到目前为止,最好的解决方案(并不理想)是创建一个自定义的
RelativeLayout
,如下所示:

public class MyCustomRL extends RelativeLayout {

    public MyCustomRL(Context context) {
        super(context);
        initView(context);
    }

    public MyCustomRL(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public MyCustomRL(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView(context);
    }

    protected void initView(Context context){

        LayoutInflater inflater = LayoutInflater.from(context);
        SeekBar_Speedometer v_speedometer = (SeekBar_Speedometer) inflater.inflate(R.layout.rl_custom_speedometer, this, false);

        addView(v_speedometer);

        RelativeLayout rl_comment = (RelativeLayout) inflater.inflate(R.layout.rl_edittext_comment, this, false);

        EditText edit = (EditText) rl_comment.findViewById(R.id.edittext_comment);
        edit.setText("Text altered at runtime");

        rl_comment.setX(112);
        rl_comment.setY(117);
        //Log.v("WHATEVER","X: "+v_speedometer.centerX); // = 0
        //rl_comment.setX(v_speedometer.centerX);
        //rl_comment.setY(v_speedometer.centerY);

        addView(rl_comment);
    }
}
这基本上是可行的,
EditText
定位在这些静态坐标上。但是,我希望编辑文本放置在
v_speedometer.centerX
v_speedometer.centerY
坐标处,但它们是0,因为尚未绘制
v_speedometer
视图


我应该怎么做呢?

如果您还没有找到任何解决方案,您可以编写一个接口,作为您的解决方案 速度计已被吸引。这意味着每当你的速度表被绘制出来时,它就会向实现你的编辑文本的类发布通知,然后在你的CustomView或UI中再次设置它们的坐标