Unwanted Android Layout Add-on

So, I have this layout file (below). As you can see, there are no indents or margins. Dimen.xml files also do not have indentation / margins. Finally, I DO NOT change the layout programmatically at all.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/root" android:padding="0dp" android:orientation="vertical"> <android.support.v7.widget.CardView android:id="@+id/toolbarholder" android:layout_alignParentTop="true" android:layout_width="match_parent" android:layout_height="wrap_content" app:cardElevation="16dp" app:cardCornerRadius="0dp"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> </android.support.v7.widget.Toolbar> </android.support.v7.widget.CardView> <ListView android:layout_below="@+id/toolbarholder" android:layout_above="@+id/cardroot" android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:divider="@null" android:dividerHeight="0dp" android:layout_marginTop="0dp" /> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/cardroot" android:layout_width="match_parent" android:layout_height="100dp" android:background="@color/transparentblack" app:cardCornerRadius="0dp" app:cardElevation="16dp" android:layout_alignParentBottom="true"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/buttonholder" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:weightSum="3"> <ImageView android:id="@+id/previous" android:layout_width="35dp" android:layout_height="35dp" android:src="@drawable/previous" android:layout_weight="1"/> <ImageView android:id="@+id/play" android:layout_width="35dp" android:layout_height="35dp" android:src="@drawable/play" android:layout_weight="1"/> <ImageView android:id="@+id/next" android:layout_width="35dp" android:layout_height="35dp" android:src="@drawable/next" android:layout_weight="1"/> </LinearLayout> <SeekBar android:id="@+id/seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/buttonholder" /> </RelativeLayout> </android.support.v7.widget.CardView> </RelativeLayout> 

Below are two screenshots from two different devices.

Lenovo k3 Note:

enter image description here

HTC Desire 550:

enter image description here

Any ideas what could be causing this?

+5
source share
3 answers

Ok guys ... thanks for your input. It turns out the “Cartographic Documentation” mentions that:

Prior to L, CardView adds an addition to its content and draws shadows in this area. This number of add-ons is maxCardElevation + (1 - cos45) * cornerRadius on the sides and maxCardElevation * 1.5 + (1 - cos45) * cornerRadius on the top and bottom.

This means that the margin is intended for drawing shadows and modeling height. One possible solution for everyone having the same problem is to use the cardUseCompatPadding attribute in your layout as follows:

 <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" app:cardElevation="0dp" app:cardUseCompatPadding="true"> </android.support.v7.widget.CardView> 

This will cause your layout to "display" the same way (the path to Lollipop // sad) on each device, regardless of the API. At least in this way we can fix the general layout, which works for all versions with this limitation in mind.

Hope this helps.

UPDATE: If you decide to go for "app: cardUseCompatPadding = true", here is another tip. Use a negative layout_margin to balance the unwanted add-on from the compatibility library. Example below:

 <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="-10dp" app:cardCornerRadius="0dp" app:cardUseCompatPadding="true" app:cardElevation="8dp"> </android.support.v7.widget.CardView> 

Thus, your layout can get rid of unwanted filling. And look at the same pre-lollipop after the candy.

Hope this helps even more. :)

+7
source

A possible reason is that HTC mobile phones especially have different types of internal layout files. Thus, Lenovo Nexus and SAMSUNG may function properly, but due to the difference between HTC in these situations, this is a big problem for many developers. If you really want it to work with HTC, I recommend the best way to get it to work on HTC in order to create your own XML files that look like Android support. I recommend that if you want to continue working, try installing your own xml file on the android map and use it. Now HTC should use your own, which are equal to all other androids, but not on HTC. I say that now it will work on all devices. But be careful, this can be long and painful if you cannot hang your own XML file. If you do this, it will probably become a breeze for you. I hope you understand me.

0
source

Have you tried to set the height for your linear layout or set it instead of matching the parent? It seems that there is no additional addition, but rather that your items in the list do not coincide with the fact that the image is even disabled.

0
source

All Articles