【问题标题】:How to put Imageview Below Listview in Android?如何在 Android 中将 Imageview 放在 Listview 下面?
【发布时间】:2014-01-23 20:36:41
【问题描述】:

我的 Activity 有一个布局,这个布局包含很多小部件。 在我从 Listview 中的 web 服务加载的活动数据中。 当列表视图被适配并填充所有数据时。 imagview 是不可见的 但是我想在加载数据时在 Listview 下面显示 Imageview。

我在activity_main.xml中的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rel_index"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f8f8f8"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/edt_search"
        android:layout_width="fill_parent"
        android:layout_height="40sp"
        android:layout_marginLeft="10sp"
        android:layout_marginRight="10sp"
        android:layout_marginTop="115sp"
        android:background="@drawable/round_corener_edittext"
        android:drawableLeft="@drawable/center"
        android:hint="@string/search"
        android:paddingLeft="5sp"
        android:paddingRight="5sp"
        android:textColor="#44e1f4" />

    <RelativeLayout
        android:id="@+id/rel_top"
        android:layout_width="fill_parent"
        android:layout_height="135sp"
        android:layout_marginBottom="25sp"
        android:background="@drawable/header" >

        <ImageView
            android:id="@+id/img_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_margin="10sp"
            android:background="@drawable/digi_logo"
            android:visibility="gone" />

        <View
            android:id="@+id/line"
            android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:layout_below="@+id/img_logo"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="20sp"
            android:layout_marginRight="20sp"
            android:background="#2391a2"
            android:visibility="gone" />

        <TextView
            android:id="@+id/txt_app"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/line"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="10sp"
            android:layout_marginTop="5sp"
            android:text="@string/txt_name"
            android:textColor="#1e7c95"
            android:textSize="14sp"
            android:visibility="gone" />
    </RelativeLayout>

    <ListView
        android:id="@+id/lst_data"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/rel_top"
        android:layout_marginBottom="10sp"
        android:clipToPadding="false" />



    <ImageView
        android:id="@+id/img_offer"
        android:layout_width="fill_parent"
        android:layout_height="70sp"
        android:layout_below="@+id/lst_data"
        android:adjustViewBounds="true"
        android:background="@drawable/offers_btn"
        android:scaleType="fitXY" />

</RelativeLayout>

如何解决我的问题。谢谢。

【问题讨论】:

  • 您需要将 List 视图的 layout_height 从 wrap_content 更改为特定值。
  • 没有一个特定的值只是针对不同的屏幕尺寸的废话。不要那样做。更好的是下面的答案,或者使用权重值。我更喜欢下面的答案;)
  • @Logi24 不是权重值只能在线性布局的上下文中使用吗?
  • 是的,但是您可以将布局切换到 LinearLayout。有了这个,你也可以做到。
  • LinearLayout 对我不起作用。Imagview 不可见

标签: android android-layout android-listview


【解决方案1】:

您当前告诉布局充气器要做的是将标题布局 rel_top 放在顶部,然后在其下方放置 ListView,然后在其下方放置 ImageView。您想要的基本上是将ImageView 锚定到显示屏底部,并在图像和标题布局之间拉伸ListView

您应该将ImageView 对齐屏幕底部,而不是将ImageView 对齐到ListView 下方

<ImageView
        android:id="@+id/img_offer"
        android:layout_width="fill_parent"
        android:layout_height="70sp"
        **android:layout_alignParentBottom="true"**
        android:adjustViewBounds="true"
        android:background="@drawable/offers_btn"
        android:scaleType="fitXY" />

并将ListView 对齐到rel_top 下方和ImageView 上方

<ListView
        android:id="@+id/lst_data"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/rel_top"
        **android:layout_above="@+id/img_offer"**
        android:layout_marginBottom="10sp"
        android:clipToPadding="false" />

【讨论】:

  • 不可以。我可以将 Imageview 放在屏幕底部。但是显示 listview 必须是在 Listview 下方显示的 imageview
  • 我不明白你想达到什么目的?你是不是想让你的图像出现在屏幕底部并在其上方显示列表视图
  • 这就是上面的代码应该做的。试一试会得到什么?
【解决方案2】:
private ImageView _imgView = null;
_imgView = new ImageView(this);
_listView.addFooterView(_imgView);

试试这个;或许能帮到你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-17
    • 1970-01-01
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多