Android ListView Map Behavior
I just noticed. When I use a layout inside my ListView I usually use a LinearLayout and then a CardView inside it. CardView has 10dp headroom and everything looks great. However, when I just use a CardView that has the same attributes, it doesn't make a difference for me. Is there something I am doing wrong?
Layout 1 (Gives me the layout I want):
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
card_view:cardBackgroundColor="@color/white"
card_view:cardElevation="2sp"
card_view:cardUseCompatPadding="true">
</android.support.v7.widget.CardView>
</LinearLayout>
Layout 2 (without any margin):
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
card_view:cardElevation="2sp"
card_view:cardUseCompatPadding="true"
card_view:cardBackgroundColor="@color/white">
</android.support.v7.widget.CardView>
+3
source to share
1 answer
I also ran into this problem. I think this is happening because the ListView is ignoring / not supporting the margin attribute.
More on this: Why LinearLayout field is ignored when used as a ListView
Side note: I would use FrameLayout around CardView, it's better in performance.
+3
source to share