Remove style from card view (radius/elevation) - android

I want to remove the corner radius from the card view.
I tried this:
card:cardCornerRadius="0dp"
card:cardElevation="0dp"
but no change.
Is it possible to do this?

Remove card_view:cardCornerRadius attribute from xml and try again.
No need to assign it 0dp.

Use app:cardCornerRadius="0dp"instead of card:cardCornerRadius="0dp"

Related

How can I remove the left padding of images in android studio?

The padding in the left the image below don't look good. I want to remove that. How can I remove that?
Please mention measurement also means "dp" or you can remove these two property from layout..
android:padding_left="0dp"
android:padding_right="0dp"
try put android:padding_left="0" and android:margin_left="0"

Android cardElevation Dynamically change

How to pragmatically increase the shadow of cardview in android on tap on it ?
I am able to change the shadow through the xml by using card_view:cardElevation But I want to increase the shadow of this on any touch or click event.
CardView has a method setCardElevation(float) and setMaxCardElevation(float) a think they can help you for your case ( set card elevation programatically). Hope to help!

How may I add a faded colour effect (screenshot shown)

Hey I would like to know how i can added such a faded color effect to my layout any help is appreciated. An example here:
Thanks
You can create a Shape Drawable with your desired gradient and set it as a background for your information view at the bottom
You can use setAlpha() method to adjust alpha level for your views and thereby get a faded effect.For handling this in xml you can use android:alpha attribute for your view.

Inherent TextView Padding

Does a TextView have some padding set by default? I'm trying to create two TextViews and I noticed that there's some padding in the TextViews without me explicitly setting it. If yes, then what's the value of it? Or where can I find more information on this?
Yes there exists font padding in android.
you could aswell disable it by
mTextView.setIncludeFontPadding(false);
or xml attribute
android:includeFontPadding="false"

Defining Z order of views of RelativeLayout in Android

I would like to define the z order of the views of a RelativeLayout in Android.
I know one way of doing this is calling bringToFront.
Is there are better way of doing this? It would be great if I could define the z order in the layout xml.
The easiest way is simply to pay attention to the order in which the Views are added to your XML file. Lower down in the file means higher up in the Z-axis.
Edit:
This is documented here and here on the Android developer site. (Thanks #flightplanner)
If you want to do this in code
you can do
View.bringToFront();
see docs
Please note, buttons and other elements in API 21 and greater have a high elevation, and therefore ignore the xml order of elements regardless of parent layout. Took me a while to figure that one out.
In Android starting from API level 21, items in the layout file get their Z order both from how they are ordered within the file, as described in correct answer, and from their elevation, a higher elevation value means the item gets a higher Z order.
This can sometimes cause problems, especially with buttons that often appear on top of items that according to the order of the XML should be below them in Z order. To fix this just set the android:elevation of the the items in your layout XML to match the Z order you want to achieve.
I you set an elevation of an element in the layout it will start to cast a shadow. If you don't want this effect you can remove the shadow with code like so:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
myView.setOutlineProvider(null);
}
I haven't found any way to remove the shadow of a elevated view through the layout xml.
I encountered the same issues: In a relative layout parentView, I have 2 children childView1 and childView2. At first, I put childView1 above childView2 and I want childView1 to be on top of childView2. Changing the order of children views did not solve the problem for me. What worked for me is to set android:clipChildren="false" on parentView and in the code I set:
childView1.bringToFront();
parentView.invalidate();
Please note that you can use view.setZ(float) starting from API level 21. Here you can find more info.
Thought I'd add an answer since the introduction of the
android:translationZ
XML field changed things a tad. The other answers that suggest running
childView1.bringToFront();
parentView.invalidate();
are totally spot on EXCEPT for that this code will NOT bring childView1 in front of any view with a hardcoded android:translationZ in the XML file. I was having problems with this, and once I removed this field from the other views, bringToFront() worked just fine.
API 21 has view.setElevation(float) build-in
Use ViewCompat.setElevation(view, float); for backward compatibility
More methods ViewCompat.setZ(v, pixels) and ViewCompat.setTranslationZ(v, pixels)
Another way collect buttons or view array and use addView to add to RelativeLayout
childView.bringToFront() didn't work for me, so I set the Z translation of the least recently added item (the one that was overlaying all other children) to a negative value like so:
lastView.setTranslationZ(-10);
see https://developer.android.com/reference/android/view/View.html#setTranslationZ(float) for more
Or put the overlapping button or views inside a FrameLayout. Then, the RelativeLayout in the xml file will respect the order of child layouts as they added.
You can use custom RelativeLayout with redefined
protected int getChildDrawingOrder (int childCount, int i)
Be aware - this method takes param i as "which view should I draw i'th".
This is how ViewPager works. It sets custom drawing order in conjuction with PageTransformer.
Check if you have any elevation on one of the Views in XML. If so, add elevation to the other item or remove the elevation to solve the issue. From there, it's the order of the views that dictates what comes above the other.
You can use below code sample also for achieving the same
ViewCompat.setElevation(sourceView, ViewCompat.getElevation(mCardView)+1);
This is backward compatible.
Here mCardView is a view which should be below sourceView.

Categories

Resources