Create custom viewgroup in android - android

I want to create a custom view
this view
and when add a view to XML I want to add static child view(textview,imageButtom and ...) into custom view like cardview and final view look like this picture
.how can we create a view?

You could start by extending an already defined layout like relative layout because creating a layout from scratch and implementing all methods in it is a little hard process. First thing came to my mind is adding a padding the custom layout for edge perspective effects so the layout don't place any view to this area. Then you can draw you perspective effect in onDispatchDraw() method. This method provide you with to draw canvas of the layout. In addition, using an drawable like nine patch as background makes things easier compared to custom drawing operation. In summary, you should give padding the layout to prevent overlapping with edge perspective. Then draw or set a background for the layout.

Related

Inherited ImageButton Background Padding

I'm creating a simple custom view. My view inherits from AppCompatImageButton with the goal of drawing some simple geometric shapes for my custom button and animating them.
If my XML view contains:
android:background="#color/transparent"
My view draws correctly inside a vertical LinearLayout, even though the android:background seems to otherwise do nothing. However, if I leave out android:background, the top and bottom displays an additional unwanted gap between the custom views.
The documentation says these two are "Related":
View.setBackgroundResource(int resid)
android:background
I've tried calling setBackgroundResource(R.color.transparent) in my Java initialization code, thinking this would do the same thing as XML android:background, but the unwanted padding won't go away. Here's a screenshot that shows the view without the android:background.
With android:background, the image fills the entire height not leaving the gap at the top and bottom.
How can I get my custom view to fill the entire drawing area without forcing an artificial android:background into the XML? The solution will also need to work if the programmer creates the custom view in Java without XML.
Thx.

how to design dynamic ui in android like the image below

i am trying to design dynamic ui layout in android to present the date like the image below. i am **facing the challenges in the creating an view as clustered in the below mail **
i tried using list view!
but the each appeares in diffrent line, it dose not lookes like the image as below! is that possible to design like this. if so how to do that?
Try to create a few custom views, e.g. this circles with dates, this labels on the left and rights with xml layouts. Next, create parent view with some container layout, e.g. FrameLayout. In this parent view override it's onDraw() method, and there manually create and add every layout. It is simple, but might be not efficent, when there are many of views

make views inside Layout match custom shape of layout

I have a custom semicircle Liner Layout in which I want to add colored views , but these views do not match the custom shape(or stay within the bounds of the Liner Layout)
When I assigned custom shape to the views
custom shape
when I assign MATCH_PARENT to the views
match parent
I want the views to fill the inside of the Liner Layout while retaining the shape of it, is there any way this can be done?
You can't create a custom shape to a view. VIews are always rectangular. If you mean you have a custom background, that doesn't make the view group a custom shape, or effect the layout of views within the group. If you want to do that, you need to override onLayout (and possibly onMeasure) and layout the individual children with the bounds you expect them to be in. Do not be surprised if you get some ugly or non-functional results like this- views weren't made to be circular.

Is it safe to draw a view that was not added to the view group using addView?

I am trying to draw a View in a ViewGroup without adding it to the child list.
I am doing this because I want to display something like a ProgressBar in the exact center of layouts like a LinearLayout so I don't want the layout to handle the measuring and layouting.
I also don't want to complicate the view hierarchy by adding extra layouts just to achieve this effect so my solution was to extend the LinearLayout, create a ProgressBar and handle measuring, layouting and drawing for that view myself.
My implementation seems to work ok from what I tested but I am wondering if there is anything I am not noticing or if there are any problems that can appear in the future.
From what I understand calling addView also sets the child view's parent and calls dispatchAttachedToWindow, these methods are package-private so I can't call them myself.
Is there any side effect that can arise from calling measure, layout and draw on a view that has no parent and that was not "attached" to a window? Is there a safer way to achieve the same effect?
Thanks.

Rendering absolutely positioned sprites over a regular Android layout

I've got a standard RelativeLayout laying out my Buttons and TextAreas. What I want to do now is be able to draw various sparks, flying cows etc. at arbitrary places on the screen on top of the whole thing. What's the best way to do this? Should I override onDraw() on the containing View and draw after calling super.onDraw()? Or is there some better way of drawing a layer on top?
You'll probably want to put your Relative layout and a custom view which isn't focusable and doesn't consume motionevents inside a FrameLayout, then override OnDraw in that custom view. That way you can call invalidate() on that view without making Android redraw everything else.

Categories

Resources