修改
我原本以为这个问题与搜索小部件和键盘有关。
原始问题
我最近将搜索小部件添加到了我的应用中。现在,当我登陆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(膨胀列表视图)
<?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>
如果您需要更多信息,请告诉我,谢谢!!
P.S。 min sdk是12。
更新
问题最终是内容并没有真正填满整个屏幕,直到图像从Volley请求加载。加载文本内容并设置列表视图的高度,随后加载的内容不会动态更改listiview高度。在生产中,这可能不是一个问题,但有没有办法确保ListView高度可以动态变化?
答案 0 :(得分:0)
听起来当打开活动时键盘正在尝试扩展。奇怪的是它保持空白并且没有显示实际的键盘,但是可能阻止键盘在开始时打开会有所帮助。尝试设置
android:windowSoftInputMode="stateHidden"
在AndroidManfest.xml中此活动的<activity>
标记中的。
答案 1 :(得分:0)
在清单中试试。
android:windowSoftInputMode="adjustResize"
和列表视图(“id”),尝试添加
android:alignParentBottom:"true"
答案 2 :(得分:0)
这最终与搜索小部件或键盘无关。尺寸是巧合的。
问题在于ListView中的每个项目都有一个通过volley从API加载的图像。 ListView的高度由首先加载的内容(即文本)设置。加载图像后,它会展开列表中的每个项目,但不会更改父ListView的高度。这留下了视图底部的丑陋空白。
根据@ mattgmg1990的建议,我将ListView的高度更改为match_parent
,以便允许延迟加载图像。