我正在制作一个具有类似 google now 界面的应用程序,其中包含内容卡片。
首先请看这张图片:http://imgur.com/oLSSvIn
我成功地创建了卡片并向其中添加了内容,但是我的 imageview 已经超出了卡片边框(阴影线)的顶部,如蓝色箭头所示。
请问如何在 ImageView 下使卡片灰色边框成为星形?我尝试为 ImageView 添加边距,为卡片添加底部/顶部填充,但没有成功。
这里是卡片 bg 的代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="0dp"/>
<solid android:color="#bdbdbd" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="0dp" />
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>
以及包含以下内容的 Activity :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:background="@drawable/friend_card_profile_bg" >
<ImageView
android:id="@+id/friendPic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/friend_testpic" />
<TextView
android:id="@+id/friendUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="4dp"
android:layout_toRightOf="@+id/friendPic"
android:fontFamily="sans-serif-condensed"
android:text="@string/profile_username"
android:textColor="#7f7f7f"
android:textSize="19dp" />
<TextView
android:id="@+id/friendLinksCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/friendUsername"
android:layout_marginLeft="6dp"
android:layout_toRightOf="@+id/friendPic"
android:fontFamily="sans-serif"
android:text="@string/profile_links_counter"
android:textColor="#acacac"
android:textSize="14dp" />
<TextView
android:id="@+id/friendFriendsCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/friendLinksCounter"
android:layout_marginLeft="6dp"
android:layout_toRightOf="@+id/friendPic"
android:fontFamily="sans-serif"
android:text="@string/profile_friends_counter"
android:textColor="#acacac"
android:textSize="14dp" />
</RelativeLayout>
谢谢
最佳答案
尝试在相对布局的底部使用 2dp 填充,这应该会调整内容,使其全部位于阴影之上。
关于android - 卡片边框上的 Imageview - 如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18263002/