Java ImageView浮动在CardView的中心
我想要一个简单的基于卡片的布局,图片在卡片的顶部。但是,每当我添加此项时,图像都会浮动在卡的垂直中心。如何在不设置负边距等任何缺陷的情况下将图像强制置于卡的顶部 我使用的XML就在这里Java ImageView浮动在CardView的中心,java,android,xml,Java,Android,Xml,我想要一个简单的基于卡片的布局,图片在卡片的顶部。但是,每当我添加此项时,图像都会浮动在卡的垂直中心。如何在不设置负边距等任何缺陷的情况下将图像强制置于卡的顶部 我使用的XML就在这里 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Rel
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EEE">
<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:background="#000000"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
>
<ImageView android:src="@drawable/edinburgh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="@id/card_view" ></ImageView>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
解决方案:
将android:layout\u alignParentTop=“@id/card\u view”
更改为android:layout\u gravity=“top”
说明:
android:layout\u alignParentTop=“@id/card\u view”
值必须是布尔值,而不是视图的id
android:layout\u alignParentTop
是RelativeLayout
子项的属性,其中cardwiew
继承自FrameLayout
,而不是RelativeLayout
解决方案:
将android:layout\u alignParentTop=“@id/card\u view”
更改为android:layout\u gravity=“top”
说明:
android:layout\u alignParentTop=“@id/card\u view”
值必须是布尔值,而不是视图的id
android:layout\u alignParentTop
是RelativeLayout
子项的属性,其中cardwiew
继承自FrameLayout
,而不是RelativeLayout
解决方案:
将android:layout\u alignParentTop=“@id/card\u view”
更改为android:layout\u gravity=“top”
说明:
android:layout\u alignParentTop=“@id/card\u view”
值必须是布尔值,而不是视图的id
android:layout\u alignParentTop
是RelativeLayout
子项的属性,其中cardwiew
继承自FrameLayout
,而不是RelativeLayout
解决方案:
将android:layout\u alignParentTop=“@id/card\u view”
更改为android:layout\u gravity=“top”
说明:
android:layout\u alignParentTop=“@id/card\u view”
值必须是布尔值,而不是视图的id
android:layout\u alignParentTop
是RelativeLayout
子项的属性,其中cardwiew
继承自FrameLayout
,而不是RelativeLayout