Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ImageView浮动在CardView的中心_Java_Android_Xml - Fatal编程技术网

Java ImageView浮动在CardView的中心

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

我想要一个简单的基于卡片的布局,图片在卡片的顶部。但是,每当我添加此项时,图像都会浮动在卡的垂直中心。如何在不设置负边距等任何缺陷的情况下将图像强制置于卡的顶部

我使用的XML就在这里

<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