custom-view
Android Custom View Constructor
You don’t need the first one, as that just won’t work. The third one will mean your custom View will be usable from XML layout files. If you don’t care about that, you don’t need it. The fourth one is just wrong, AFAIK. There is no View constructor that take a Map as the third … Read more
How can I get the canvas size of a custom view outside of the onDraw method?
For drawing purposes, you should not really use the dimensions of the Canvas object. Just use the dimensions provided to you in the onSizeChanged method. You can either store the dimensions for use in the onDraw method or resize/draw to a backing bitmap that you can draw with later. Update: Quickly whipped up some code, … Read more
Camera with Custom View
You might be trying using UIImagePickerController. But I know this one solution to your problem. You can do it easily using AVCamCaptureManager and AVCamRecorder classes. Apple has a demo program build on its developer site here. It is named AVCam. In simple words what it does is when you click to open the camera, it … Read more
How to get an enum which is created in attrs.xml in code
There does not seem to be an automated way to get a Java enum from an attribute enum – in Java you can get the numeric value you specified – the string is for use in XML files (as you show). You could do this in your view constructor: TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.IconView, … Read more
Can a custom View know that onPause has been called?
Yes you can using below code, @Override protected void onVisibilityChanged(@NonNull View changedView, int visibility) { super.onVisibilityChanged(changedView, visibility); if (visibility == View.VISIBLE) //onResume called else // onPause() called } @Override public void onWindowFocusChanged(boolean hasWindowFocus) { super.onWindowFocusChanged(hasWindowFocus); if (hasWindowFocus) //onresume() called else // onPause() called } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); // onDestroy() called } @Override … Read more
How to create custom view programmatically in swift having controls text field, button etc
The CGRectZero constant is equal to a rectangle at position (0,0) with zero width and height. This is fine to use, and actually preferred, if you use AutoLayout, since AutoLayout will then properly place the view. But, I expect you do not use AutoLayout. So the most simple solution is to specify the size of … Read more
Android ImageView size not scaling with source image
What about changing your ImageViews to use android:layout_height=”fill_parent”? Edit – took me a while to find, but looking at the source helped me pinpoint adjustViewBounds. You might want to try adding android:adjustViewBounds=”true” to your ImageViews. Surprisingly, this defaults to false.
android data binding with a custom view
In your Custom View, inflate layout however you normally would and provide a setter for the attribute you want to set: private MyCustomViewBinding mBinding; public MyCustomView(…) { … LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mBinding = MyCustomViewBinding.inflate(inflater); } public void setMyViewModel(MyViewModelObject obj) { mBinding.setMyViewModel(obj); } Then in the layout you use it in: <layout xmlns…> <data> … Read more