Android Custom View Constructor

后端 未结 3 1483
独厮守ぢ
独厮守ぢ 2020-11-27 15:16

I\'m learning about using Custom Views from the following:

http://developer.android.com/guide/topics/ui/custom-components.html#modifying

The description says

3条回答
  •  失恋的感觉
    2020-11-27 16:08

    Here's a my pattern (creating a custom ViewGoup here, but still):

    // CustomView.java
    
    public class CustomView extends LinearLayout {
    
        public CustomView(Context context) {
            super(context);
            init(context);
        }
    
        public CustomView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init(context);
        }
    
        public CustomView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            init(context);
        }
    
        private void init(Context ctx) {
            LayoutInflater.from(ctx).inflate(R.layout.view_custom, this, true);
                // extra init
        }
    
    }
    

    and

    // view_custom.xml
    
    
        
    
    

提交回复
热议问题