【问题标题】:Elevation increases with list position海拔随着列表位置的增加而增加
【发布时间】:2017-05-29 12:06:43
【问题描述】:

我有一个带有 CardView 的 recyclerview。即使我没有明确指定海拔,当项目到达屏幕底部时,海拔也会增加。没有在其他地方看到过这种行为,这是什么原因造成的?

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/card_layout"
    app:cardElevation="6dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true"
    android:foreground="?android:attr/selectableItemBackground"
    android:fitsSystemWindows="true"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/schedule_card_height"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <TextView
                android:id="@+id/schedule_item_category"
                style="@style/Base.TextAppearance.AppCompat.Caption"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@drawable/background_eventlist_category"
                android:gravity="center"
                android:padding="5dp"
                android:textAllCaps="true"
                tools:text="Interview"/>
        </RelativeLayout>

        <View android:layout_height="match_parent"
              android:layout_width="1dp"
              android:background="@color/colorIcons"

              />

        <RelativeLayout
            android:id="@+id/schedule_item_actions"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="wrap_content"
            android:background="@drawable/rounded_white"
            android:padding="12dp">

            <ProgressBar
                android:id="@+id/schedule_item_progress"
                style="?android:attr/progressBarStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:visibility="gone"/>


            <TextView
                android:id="@+id/schedule_item_title"
                style="@style/TextAppearance.AppCompat.Subhead"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="top|center_vertical"
                android:layout_alignParentLeft="true"
                android:layout_above="@+id/schedule_item_date"
                android:layout_alignParentTop="true"
                android:layout_toLeftOf="@+id/schedule_item.popup"
                android:ellipsize="end"
                android:maxLines="2"
                tools:text="Awesome event because i say so"/>

            <TextView
                android:id="@+id/schedule_item_date"
                style="@style/TextAppearance.AppCompat.Caption"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:layout_alignParentLeft="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:ellipsize="end"
                android:textAllCaps="true"
                android:maxLines="1"
                tools:text="25th April, 5PM (GMT)"/>

            <ImageView
                android:id="@+id/schedule_item.popup"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:src="@drawable/ic_dots"/>

        </RelativeLayout>

    </LinearLayout>

</android.support.v7.widget.CardView>

【问题讨论】:

  • 请显示您的 xml 布局文件。
  • 显示你的 xml 代码。尝试输入useCompatPadding true 并将高度设置为 1,2 或等。
  • 我刚发了
  • app:cardElevation="6dp"你说你没有指定?
  • 是的,我只是在测试,不管我放不放它都会发生

标签: android


【解决方案1】:

灯光位于设备顶部附近,向下朝向显示屏倾斜,因此项目越低,阴影距离越大。

【讨论】:

  • 我认为.. 他正在使用自拍闪光灯.. :D 但逻辑是可靠的。
【解决方案2】:
    <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"

                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">  
      <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/card_layout"
            app:cardElevation="6dp"
            app:cardPreventCornerOverlap="false"
            app:cardUseCompatPadding="true"
            android:foreground="?android:attr/selectableItemBackground"
            android:fitsSystemWindows="true"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/schedule_card_height"
                android:orientation="horizontal">

                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1">

                    <TextView
                        android:id="@+id/schedule_item_category"
                        style="@style/Base.TextAppearance.AppCompat.Caption"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:background="@drawable/background_eventlist_category"
                        android:gravity="center"
                        android:padding="5dp"
                        android:textAllCaps="true"
                        tools:text="Interview"/>
                </RelativeLayout>

                <View android:layout_height="match_parent"
                      android:layout_width="1dp"
                      android:background="@color/colorIcons"

                      />

                <RelativeLayout
                    android:id="@+id/schedule_item_actions"
                    android:layout_width="0dp"
                    android:layout_weight="2"
                    android:layout_height="wrap_content"
                    android:background="@drawable/rounded_white"
                    android:padding="12dp">

                    <ProgressBar
                        android:id="@+id/schedule_item_progress"
                        style="?android:attr/progressBarStyle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:visibility="gone"/>


                    <TextView
                        android:id="@+id/schedule_item_title"
                        style="@style/TextAppearance.AppCompat.Subhead"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="top|center_vertical"
                        android:layout_alignParentLeft="true"
                        android:layout_above="@+id/schedule_item_date"
                        android:layout_alignParentTop="true"
                        android:layout_toLeftOf="@+id/schedule_item.popup"
                        android:ellipsize="end"
                        android:maxLines="2"
                        tools:text="Awesome event because i say so"/>

                    <TextView
                        android:id="@+id/schedule_item_date"
                        style="@style/TextAppearance.AppCompat.Caption"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentEnd="true"
                        android:layout_alignParentBottom="true"
                        android:ellipsize="end"
                        android:textAllCaps="true"
                        android:maxLines="1"
                        tools:text="25th April, 5PM (GMT)"/>

                    <ImageView
                        android:id="@+id/schedule_item.popup"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentEnd="true"
                        android:src="@drawable/ic_dots"/>

                </RelativeLayout>

            </LinearLayout>

        </android.support.v7.widget.CardView>
            </LinearLayout>

【讨论】:

  • 这基本上是在放置一个包裹 CardView 的 LinearLayout 对吧?
猜你喜欢
  • 2021-11-22
  • 1970-01-01
  • 2013-09-02
  • 1970-01-01
  • 1970-01-01
  • 2018-01-29
  • 1970-01-01
  • 2023-03-30
相关资源
最近更新 更多