【发布时间】: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