How to make UI shadow to any view - android

thank you for answering me
I just want to know how i can make the shadow below this card
I already tried several ways like Elevation... but it didn't work for me.
I searched a lot about it and I found that website :
Shadow generator
But i'm wondering if there is another way, using xml or anything else.

You are half right in that elevation is required for a shadow effect.But note this is only applicable to view that are not buttons. For buttonViews you can add a statelist animator that handles the properties of a button for all its states.Also if you are using something like a textView that does not have any margins you might as well use a background to show the shadow as follows:
android:elevation="30dp"
android:background="#000"
For other views, this means simply adding the elevation attribute as shown above and the background is not required
This link will help:
How to provide shadow to Button

Related

Android custom rectangle

In my app i need to create cardview with curved top and bottom lines, like this:
I tried to search answer on stackoverflow and google but i haven't found anything. Also i tried to make it via xml, but i couldn't.
Can anyone help me with this? I can't use it like image background because i need to change background color when i click on card and i have a lot of such card in my recyclerview and a lot of different colors for every card.
Thx.
You need to use a custom shape a la this as the background of the view. edit see this post

Circular View with Button Press Effect

I am looking for a custom component to design a circular remote control view like the image below with different button and background color.
Each button should be touchable with proper press effect. I did find a useful library with this I am able to create somewhat similar design but still there are lots of improvement required like Press effect/ Inner and outer circle padding radius etc. Please help me to find the better option for this.
I think tihs is your answer.
You can download here.
https://code.google.com/p/radial-menu-widget/
You could make your own class extending view. You will then be able to override onDraw() and draw whatever you want.
You could also use default android Button with a custom xml selector defined with a different image ressource for pressed/not pressed states.

How do you get ripple effect to extend past view bounds?

The touch ripple effect here expands past its bounds. How is this done?
EDIT: I am okay with this working on 5.0+ only.
I've read from a few places that:
If you want to apply the standard ripple effect on Android 5.0: API 21
or more, which should not be limited to your view (unbounded ripple),
just apply to your View background :
android:background="?android:attr/selectableItemBackgroundBorderless"
I have tested it, what is happening here is that the ripple is not on the buttons, but on the background object. So the ripple is not actually extending past the buttons bounds here, but rather extending to the bounds of the background wrapper card object.
To replicate what you see in the picture,
1. Make a new layout. I would use either a relative layout or linearlayout
2. Add the upper EditText ("Add a quick note"), and then and the four lower buttons, all with clear backgrounds, but with gray borders like above.
3. Set your ripple animation on the background of the layout you put the buttons in, and be sure to set android:clickable="true"on your layout!
That gave me the same effect as your picture.
doc already mentioned it
//An unbounded red ripple.
<ripple android:color="#ffff0000" />
https://developer.android.com/reference/android/graphics/drawable/RippleDrawable.html

How to create a "reveal" effect that's not circular?

Android has a nice reveal animation (called "CircularReveal") that has a circle shape (link here and here) .
I was wondering: is it possible to do it in other shapes too?
For example, reveal a view from top to bottom, in a rectangle shape, as such:
XXX XXX XXX
... => XXX => XXX
... ... XXX
A video of how it looks like can be found here.
In the previous way to do it, I've used a customized ObjectAnimator (link here) that changes the layout params (which works, but it's a workaround and it's not quite customizable, and it will probably not work on this case), but I wonder if there's a new way to do it, something easier and more customizable.
Also, is it possible to make this kind of animation work on previous Android versions, and not just Lollipop?
It's just that I've seen "Google Now Launcher"'s search-history appear this way, and I wonder how to make a similar thing.
You could create a New Animator like this http://cogitolearning.co.uk/?p=1451 and define your own rectangular animator. Here is a reference link to the GitHub source code posted by the author.
The Google Now search history animation just looks like a simple translate to me. It looks like the top search bar is in front of the history drop down. By animating the views in front (of your view you want to be revealed) to go down, I think you would get the reveal you are looking for. See: https://stackoverflow.com/a/19766034/2832027
The only solution I've come up with is to put a view as a second layer (on top of the listView) that is identical to the background, which has a scaled down animation.
so it's like that in the layout XML:
<FrameLayout >
<ListView/>
<View/>
</FrameLayout>
This should work, but it's more of a workaround.
Also, it has some disadvantages:
another layer means more overdraw.
might be tricky in case you have a complex background.
it's probably not as nice to use as a real reveal-animation.
Check my project: https://github.com/mageRabbitStudios/coolandroidstuff/tree/master/MyCircularReveal_12_3_19
In there you can create any reveal animations you wish. It will sound complicated but is quite simple. I created custom ImageView where I access the "clipPath" property of its canvas.(The only way I found to change the clip mask of a view, there is simpler solution shown on the third ImageView where I access only clipBounds property of the ImageView and during that it is not neccessary to create custom view) I update the clipPath on every draw which is called only during the animation's execution using AnimatorUpdateListener and using ObjectAnimators and custom Evaluator I manage to create from circle to rectangle reveal animation :)
Convert it to Java if you don't understand Kotlin

How do you rearrange buttons where you want them in Eclipse?

Hey guys I am having trouble with placing my buttons in my XML layout. I already have a background and was just trying to put 3 buttons near the middle and thats where I'm having trouble. I know about center gravity and all that but could you help me? Also, If I made my own buttons can I just import them using the image button thing, or is that not right? Thanks for the help!
PS: Also, there is a big white box around my button. How do I get that to go away?
I posted this answer to your duplicate question, so I'll also post it here. :)
You can rearrange elements of your layout by editing the XML directly or by dragging and dropping in the outline view or the graphical layout view (I find the latter harder to do reliably).
To use your custom views, click on the "Custom & Library Views" button in the graphical layout palette, or just type in the fully qualified class name as the view tag in the XML.
If you use Image button you can set your custom Image to src property or background property. If youi chose src you should add android:background="#null".
But I would recommend to use background property while if you use 9-patch png (who knows maybe tomorow you will use 9-patch) they would not stretch if you set it in src.

Categories

Resources