ImageView显示在ListView上方

时间:2017-11-08 11:21:45

标签: android android-layout

我有一个由ListView和Image组成的布局。
我想将图像放在Listview上方(在左上角),但在运行应用程序时,只有Listview可见,Image在Listview后面。 我想显示图像而不是列表的第一项。
有什么建议吗?
以下是布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@android:color/background_light"
    android:orientation="vertical">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="100">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/back"
        android:id="@+id/back_button"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="10dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_gravity="left"
        android:focusable="true"
        />

    </FrameLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <ListView

        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:choiceMode="multipleChoice">

    </ListView>

    </FrameLayout>
</RelativeLayout>

</LinearLayout>

4 个答案:

答案 0 :(得分:0)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@android:color/background_light"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/back"
        android:id="@+id/back_button"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="10dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_gravity="left"
        android:focusable="true"
            />

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:choiceMode="multipleChoice">

        </ListView>

</LinearLayout>

答案 1 :(得分:0)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:paddingBottom="@dimen/activity_vertical_margin"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:paddingTop="@dimen/activity_vertical_margin"
              android:background="@android:color/background_light"
              android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="100">

        <FrameLayout
            android:id="@+id/frameLayoutImagevIew"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@drawable/back"
                android:id="@+id/back_button"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="10dp"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_gravity="left"
                android:focusable="true"
                />

        </FrameLayout>

        <FrameLayout
            android:layout_below="@id/frameLayoutImagevIew"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ListView

                android:id="@android:id/list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:choiceMode="multipleChoice">

            </ListView>

        </FrameLayout>
    </RelativeLayout>



</LinearLayout>

答案 2 :(得分:0)

尝试在ImageView中设置高程值。例如:android:elevation="5dp"。这应该可以解决您的问题。希望它有所帮助。

答案 3 :(得分:0)

您可以使用 headerview 将图片添加到顶部,如

listview.addHeaderView(view);// view which contains that image

试试这个。

相关问题