Custom card view shape - java

I have an idea for a card item. But I don't know what is the best way to implement this. I can't imagine, how to do this with xml (how to cut off that half of the circle?), or how to do this using canvas? Extend card view and redefine background or?

This should set you down the right path: http://developer.android.com/tools/help/draw9patch.html
It allows you to define how a custom image will stretch.
I recommend you use a dialog or custom view with the 9patch image set as the background. If the custom view is a relative layout then you can just center the textview within the relative layout.
Alternatively, if you really don't want to use an image, you can create a custom view and override the onDraw method. #see http://developer.android.com/training/custom-views/custom-drawing.html

Related

How to make dimming effect of Youtube when motionLayout transitions from start to end?

I'm trying to make this effect but has no idea, how to achieve it:
My idea is to have a Frame Layout which wraps the video fragment, and the Video fragment has motion Layout as its root layout. So, Frame Layout is in main Activity, but motion Layout is inside a .xml file, which will soon be inflated as the Video fragment's layout. It looks something like this (The frag container will match parent in its width and height):
My questions are:
Is this a good idea to make this transition?
How to make the dimming effects that YouTube has? I'm planning to use this Listener for tracking the transition but has no idea how to make the slowly dimming effect :(. MotionLayout.TransitionListener
Any idea?
One way I can think of cover the screen with a a View that is
#000000 and transition the views color to #FF000000 using a custom Attribute.
The View would need to be gone, Invisible, or translationZ = -1 at the start

Design decision for custom view

I want to design a custom card view which displays information about a duel in an android app. Here is a screenshot of what the view looks like right now.
The image and the green button should be clickable, however, this design is currently done in one custom view extending CardView. The green button is a Rectangle and the polygon is a filled Path which overlays the button.
Because I have done everything in one onDraw() method, there is no onClick() method for solely the button or solely the image. Is there any clever way to do this? Maybe I'm conceptually wrong somewhere?
My thoughts so far:
Have a transparent button on top of the green button in the xml
Maybe there is a way to include a button in the onDraw() method
Make the whole view clickable and include the image in the xml
This is how I solved it now. I changed the custom view to only display the skewed rectangle. The other resources were created in a seperate xml file. With an <include />, I was able to place the rectangle over the button.

Overriding: same onDraw for many Views (Button, TextView) elements

I need to draw custom borders in android to all of the views on my screen. Every view will have different parameters. To do this, I thought about making new CustomBotton, CustomTextView etc. classes and redefine their onDraw() methods. But the methods will contain the same code, so it's not nice to
make new classes for those Views and
rewrite the same onDraw() method with the same code.
Is there a more elegant/faster way to do this?
Do something like this for simple and fast solution (Doing things quick always has a performance trade off).
Dont deal with onDraw for anyview.
Make a single class extending LinearLayout.
2.1 Set Background of this Linearlayout as color of your border.
2.1.1 - More better read border color attribute from xml at runtime.
2.2 Set its padding as width of your border.
2.3 Set its width and height as wrap_content and wrap_content respectively.
Add single view to this LinearLayout. Either programatically or via xml.
<com.example.BorderLinearLayout >
<ImageView /> // or whatever. But a single view or viewgroup only
</com.example.BorderLinearLayout>
Hope this helps

Creating a view using overlay JPanels

I want to create a view in swing like in the picture. I managed to create the using three horizontal panels. My question is that I can create same view using only one horizontal panel ?
In Swing, no you cannot do it with a single JPanel.
You can write your own layout manager, like they show in Creating a Custom Layout Manager.

Does a paint app on an android phone require an xml layout?

Do i need a layout for a view for when the user "paints" on the screen? And what type of layout should i have? Can it be virtually anything? Like a white screen? Thanks.
You need to use at least one layout which will act as your holder View.
It can be a white screen or whatever you want etc.Instead of programming creating all the views make a holder View for your paint stuff and do the painting on it.
No, XML layouts are optional. You can create it programmatically:
View view = new MyCustomPaintView(context);
setContentView(view);
But XML layouts are very usefull (and strictly recommended) when you need to place many Views on a screen.

Categories