结合了两种内容查看的 [英] Combine Two ContentView's

查看:73
本文介绍了结合了两种内容查看的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个应用程序,将包含按钮和图纸。我想这样做是两者结合到一个屏幕。

I am currently writing an app that will contain buttons and drawings. What I would like to do is combine the two onto the one screen.

setContentView(R.layout.activity_login_page);
setContentView(drawView);

}

class DrawView extends View {
    Paint paint = new Paint();

    public DrawView(Context context) {
        super(context);
        paint.setColor(Color.GREEN);
    }
    @Override
    public void onDraw(Canvas canvas) {

         super.onDraw(canvas);

         paint.setStyle(Paint.Style.FILL_AND_STROKE);
         canvas.drawCircle(50, 100, 200, paint);
         canvas.drawLine(20, 10, 50, 20, paint);

    }
}
}

当我设置的内容,以R.layout.activity_login_page我只得到我已经加入到XML文件布局的按钮。当我有被设置在两个布局如上,我只得到了圈和线出现,而不是按钮。我怎样才能将二者结合起来?

When I set the content view to R.layout.activity_login_page I only get the button that I have added to the XML Layout file. When I have the two layouts being set as above, I only get the circle and the line appear and not the button. How can I combine the two?

推荐答案

,你需要做到以下几点:

in order to use your newly customized view within a layout, you need to do the following:


  1. 创建所有自定义视图类需要构建函数中,或者至少一个包括上下文和属性。

  1. create all of the needed CTORs for your custom view class, or at least the one that includes the context and the attributes.

在布局文件(在res xml文件/布局)把新的视图,包括它的完整路径标签,或者使用UI设计师和拖放(这是在自定义视图类)。

in the layout file (the xml file in res/layout) put the new view as a tag that includes its full path, or use the UI designer and drag and drop it (it's in the "custom views" category).

如果你想处理自己的自定义属性,您需要了解的多一点,而在attr.xml文件在res添加属性/值的文件夹,并检查了CTOR值(的自定义视图)。

if you wish to handle your own customized attributes, you need to learn a bit more of it, and add attributes in the attr.xml file in the res/values folder, and also check the values in the CTOR (of the custom view).

这篇关于结合了两种内容查看的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆