【发布时间】:2015-05-30 01:54:53
【问题描述】:
我已经在 5.0 之前的设备上测试过这段代码,它们似乎都可以工作。 当我在 5.0 以上的任何东西上尝试它时,图像会被剪裁,因为它们的 z 位置不在前面。
这是我要修复的布局。问题是 CardView 下面的 5 个图像。我希望它们在某种程度上“附着”到 CardView”,即 CardView 有 5 张图像挂在上面。它们应该在卡片上大约 50% 和 50% 折扣。我已经在 android 4.4 上以负布局边距实现了这一点及以下,但当我在 5.0+ 上查看此图像时,图像位于 CardView 下方而不是其顶部。
我尝试将 CardView 封装在框架布局中并这样做,但视图完全消失了。
任何帮助将不胜感激!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipChildren="false">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/card_rep_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rep_dean" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp">
<ImageView
android:id="@+id/card_image_type"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/reps_small_image" />
<TextView
android:id="@+id/card_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/card_image_type"
android:textColor="@color/reps_icon" />
<TextView
android:id="@+id/card_rep_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/card_type"
android:layout_toRightOf="@id/card_image_type"
android:textColor="#333333"
android:textSize="15dp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/card_rep_bottom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/card_rep_name"
android:layout_toRightOf="@id/card_image_type"
android:orientation="horizontal">
<ImageView
android:id="@+id/card_rep_office_identifier"
android:layout_width="10dp"
android:layout_height="10dp"
android:visibility="gone" />
<TextView
android:id="@+id/card_rep_office"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Space
android:layout_width="5dp"
android:layout_height="wrap_content" />
<View
android:layout_width="2dp"
android:layout_height="10dp"
android:layout_marginTop="7dp"
android:background="@android:color/darker_gray" />
<Space
android:layout_width="5dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/card_rep_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:visibility="invisible" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<ImageView
android:id="@+id/image_one"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_below="@id/card_view"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="-25dp"
android:background="@drawable/social_bottom" />
<ImageView
android:id="@+id/image_two"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="@id/card_view"
android:layout_marginLeft="10dp"
android:layout_marginTop="-25dp"
android:layout_toLeftOf="@id/image_one"
android:background="@drawable/bills_bottom" />
<ImageView
android:id="@+id/image_three"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="@id/card_view"
android:layout_marginLeft="10dp"
android:layout_marginTop="-25dp"
android:layout_toLeftOf="@id/image_two"
android:background="@drawable/reps_gray_bottom" />
<ImageView
android:id="@+id/image_four"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="@id/card_view"
android:layout_marginLeft="10dp"
android:layout_marginTop="-25dp"
android:layout_toLeftOf="@id/image_three"
android:background="@drawable/polls_bottom" />
<ImageView
android:id="@+id/image_five"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="@id/card_view"
android:layout_marginTop="-25dp"
android:layout_toLeftOf="@id/image_four"
android:background="@drawable/news_bottom" />
</RelativeLayout>
</LinearLayout>
【问题讨论】:
-
我还尝试为我的一个布局设置负边距,但没有成功。
标签: android android-cardview margin