[英]Blank space at bottom of ListView not filled
编辑
我原本以为这个问题与搜寻小工具和键盘有关。
原始问题
我最近将搜索小部件添加到了我的应用中。 现在,当我登陆MainActivity时,将在弹出键盘的位置立即剪切视图。 内容在那个较小的框中滚动。 当我点击操作栏中的搜索小部件时,键盘会弹出并填充空白。 当我合上键盘时,我的视图就完整了,没有空格。 查看这张照片,了解我的意思。
这是我的布局
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null" />
</LinearLayout>
feed_item.xml(使listview膨胀)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/feed_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/feed_item_margin"
android:layout_marginRight="@dimen/feed_item_margin"
android:layout_marginTop="@dimen/feed_item_margin"
android:background="@drawable/bg_parent_rounded_corner"
android:orientation="vertical"
android:paddingBottom="@dimen/feed_item_padding_top_bottom"
android:paddingTop="@dimen/feed_item_padding_top_bottom" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="@dimen/feed_item_padding_left_right"
android:paddingRight="@dimen/feed_item_padding_left_right" >
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/vendorPic"
android:layout_width="@dimen/feed_item_vendor_pic_width"
android:layout_height="@dimen/feed_item_vendor_pic_height"
android:scaleType="fitCenter" >
</com.android.volley.toolbox.NetworkImageView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/feed_item_profile_info_padd" >
<TextView
android:id="@+id/timestamp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/timestamp"
android:textSize="@dimen/feed_item_timestamp" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/txtHeadlineMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="@dimen/feed_item_status_pad_left_right"
android:paddingRight="@dimen/feed_item_status_pad_left_right"
android:paddingTop="@dimen/feed_item_status_pad_top" />
<com.example.myapp.FeedImageView
android:id="@+id/feedImage1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:scaleType="fitXY"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
这是我的可搜索配置xml。
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint" >
</searchable>
让我知道您是否还需要继续,谢谢!
PS min sdk为12。
更新
问题最终是,直到从Volley请求中加载图像后,内容才真正覆盖整个屏幕。 文本内容已加载并设置了listview的高度,随后加载的内容并未动态更改listiview的高度。 在生产中这可能不会有问题,但是有没有办法确保ListView的高度可以动态变化?
听起来好像在打开活动时键盘正在尝试展开。 奇怪的是,它保持空白并且没有显示实际的键盘,但是也许防止一开始打开键盘会有所帮助。 尝试设定
android:windowSoftInputMode="stateHidden"
在AndroidManfest.xml中为此活动的<activity>
标记中。
试试在清单中。
android:windowSoftInputMode="adjustResize"
并添加到您的列表视图(“ id”)中,尝试添加
android:alignParentBottom:"true"
最终与搜索小部件或键盘无关。 大小是巧合。
问题在于,ListView中的每个项目都有一个图像,该图像是通过凌空从API加载的。 ListView的高度由首先加载的内容(即文本)设置。 加载图像后,它会扩展列表中的每个项目,但不会更改父级ListView的高度。 这在视图底部留下了难看的空白。
根据@ mattgmg1990的建议,我将ListView的高度更改为match_parent
,以允许后期加载图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.