Android listview下的Textview
嘿,伙计们,我的活动中有一个xml 这是我的密码:Android listview下的Textview,android,android-listview,textview,Android,Android Listview,Textview,嘿,伙计们,我的活动中有一个xml 这是我的密码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView and
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview_corners" >
</ListView>
<ListView
android:id="@+id/list2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
</ListView>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Prices from:" />
<ImageView
android:id="@+id/ivprivatecell"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:src="@drawable/privatecell" />
</LinearLayout>
但是,一旦加载了listview,我就看不到textview和imageview了!怎么办?只有listview的才可见!谢谢为每个列表视图添加一个权重为1的布局:
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/listview_corners"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/list2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone" >
</ListView>
列表视图很贪婪。他们会假设他们需要整个屏幕的高度。如果您想显示下方的内容,则需要使用固定高度或相对高度,将项目固定在屏幕底部,并使用layout_alignParentBottom和通过layout_Upper强制在其上方布局的列表,将权重添加到包含ListView的布局中,并将权重添加到textview和imageview中,确保权重小于1,且总和为1。最后,将高度设置为0dp。使用此选项,您可以设置希望每个视图在每个屏幕大小上显示的屏幕百分比我不知道这是否适用于您,但我会将父布局更改为相对视图
,然后将图像视图
附加到底部,将文本视图
放在其上方,并将两个列表视图
在那些使用RelativeLayout
属性的上面
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview_corners"
android:layout_above="@id/list2" >
</ListView>
<ListView
android:id="@+id/list2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_above="@id/textView1" >
</ListView>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Prices from:"
android:layout_above="@id/ivprivatecell />
<ImageView
android:id="@+id/ivprivatecell"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentBottom="true"
android:src="@drawable/privatecell" />
</RelativeLayout>
设置列表视图小部件0dp的高度而不是包装内容我收到一个错误:可疑大小:这将使视图不可见,应与布局一起使用_weight@TorrentLookup那么我能做什么呢?“1”,就像我上面的例子一样。FD u我想知道你是否能帮我回答这个问题。我保证,这不是那种“为我解决这个”的问题。