Android: Custom view based on layout: how?

前端 未结 1 1538
一个人的身影
一个人的身影 2020-12-31 22:51

I am building a Android app and I am a bit struggling with custom Views.

I would like to have a reusable View that consist of a few standard layout elements. Let\'s

相关标签:
1条回答
  • 2020-12-31 23:28

    Here are some rough steps regarding one way to create a custom aggregate view:

    1. extend RelativeLayout
    2. Provide a constructor in your new class that accepts Context and AttributeSet, making sure to call the superclass first. Do no add anything at this point. Wait until the next step.
    3. override the onFinishInflate method, where you can add your contents through Java code or inflating an XML resource
    4. Add any event handlers, etc
    5. Optionally create a resources file if your widget will require attributes to be set.

    0 讨论(0)
提交回复
热议问题