Android 键盘存在时调整ListView的大小
当有软件键盘时,我在调整listview的大小方面有点问题。基本上,我使用的是谷歌地图API,地图覆盖了整个屏幕,带有透明的actionbar,我在地图上有一个车辆列表,从右侧滑入。当右面板退出时,整个布局如下所示:Android 键盘存在时调整ListView的大小,android,android-layout,android-fragments,android-listview,Android,Android Layout,Android Fragments,Android Listview,当有软件键盘时,我在调整listview的大小方面有点问题。基本上,我使用的是谷歌地图API,地图覆盖了整个屏幕,带有透明的actionbar,我在地图上有一个车辆列表,从右侧滑入。当右面板退出时,整个布局如下所示: 现在我使用的是android:WindowsOfInputMode=“adjustPan”,所以当我聚焦编辑文本并将键盘滑出时,看起来是这样的: 这不好,因为我看不到完整的车辆列表。我曾尝试使用android:WindowsOfInputMode=“adjustResize”,但由
现在我使用的是android:WindowsOfInputMode=“adjustPan”,所以当我聚焦编辑文本并将键盘滑出时,看起来是这样的: 这不好,因为我看不到完整的车辆列表。我曾尝试使用android:WindowsOfInputMode=“adjustResize”,但由于我使用的是透明的actionbar,因此会发生以下情况: 我可以看到整个listView,它滚动得很好,但我的EditText现在在ActionBar下。基本上,我想要实现的是这两种情况的结合,因此它将如下所示: 现在这是片段的布局和我的列表
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
tools:context="hidden">
<EditText
android:id="@+id/vehicle_search_edit_text"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:focusable="true"
android:hint="Search"
android:imeOptions="actionSearch"
android:singleLine="true" />
<ListView
android:id="@+id/list_vehicles"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/vehicle_search_edit_text"
android:animateLayoutChanges="true"
android:fastScrollEnabled="true"
/>
</RelativeLayout>
这是我主要活动的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/layout_root_map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/layout_root_vehicles"
android:layout_width="350dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
<RelativeLayout
android:id="@+id/layout_root_settings"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
我熟悉以编程方式设置布局的高度,因为我已经使用嵌套listfragment的布局进行了设置。ActionBar必须保持透明,因为这是我的老板想要的。在清单文件中,在活动中添加
android:windowSoftInputMode=“adjustPan”
。
比如说,
<activity
android:name="com.sample.ListViewsActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
</activity>
我想,这就解决了你的问题。试试看。API说
TRANSCRIPT\u MODE\u ALWAYS\u SCROLL=无论当前可见哪些项目,列表都将自动滚动到底部
setTranscriptMode(int mode)=将列表或网格置于转录模式
请测试一下,看看是否有效
setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
.我认为,由于您的actionbar与Google Maps使用的actionbar相似,因此它通常占用的空间被认为可供其他布局使用,在您的情况下,就是片段。您可以尝试为片段容器指定填充或边距,如:
android:paddingTop="?android:attr/actionBarSize"
(操作栏的大小)
连同
android:windowSoftInputMode="adjustResize"
这应该行得通
如果填充值不满足您的要求,请手动提供更合适的值。在AndroidManifest.xml中添加:
<activity android:name=".MainActivity"
android:windowSoftInputMode="stateHidden|adjustResize"/>
</activity>
为了你的活动
并添加两个参数:
<ListView
android:stackFromBottom="true"
android:transcriptMode="normal"/>
我现在使用的是android:windowSoftInputMode=“adjustPan”
,它看起来像第二张图片,我在问题中已经说明了这一点,所以这对我不起作用。我必须更改MainActivity.xml并将alignParentBottom更改为alignParentTop,但这是可行的,所以我将此标记为答案,谢谢你,它是否与android:paddingTop=“?android:attr/actionBarSize一起工作?或者你是否必须更改值?我这样问是因为我自己没有机会测试它。是的,它工作得很好,真不敢相信我自己没有弄明白