android - 为什么显示键盘时我的视图不向上滑动?
问题描述
我正在使用以下活动布局。
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
app:panelHeight="0dp"
app:shadowHeight="0dp"
app:overlay="true" >
<RelativeLayout android:id="@+id/rootRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/location"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/activity_main_map" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/toolbarThemeFakeDark"
android:background="@drawable/trans_toolbar_bg"
android:layout_margin="16dp"
android:subtitle="test">
<ImageView
android:id="@+id/wordmark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/wordmarkwhite"
android:contentDescription="@string/wordmark" />
</androidx.appcompat.widget.Toolbar>
<androidx.appcompat.widget.Toolbar android:id="@+id/timeBar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@drawable/trans_toolbar_bg"
android:layout_marginBottom="24dp"
android:layout_alignParentBottom="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginStart="4dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="20dp" >
<SeekBar
android:id="@+id/maxTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:progress="100"
android:hapticFeedbackEnabled="true"
android:layout_alignStart="@+id/timeNumber"
style="@style/MapSeekBar"
android:thumb="@drawable/map_seekbar_thumb" />
<TextView android:id="@+id/timeNumber"
android:background="@drawable/map_seekbar_thumb"
android:gravity="center"
android:layout_width="32dp"
android:layout_height="32dp"
android:textColor="@color/cpb_grey"
android:layout_marginStart="8dp"
android:layout_marginTop="0dp" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<!--- Where all the fragments live -->
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="20dp"/>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
<fragment android:name="com.myapp.FragmentLeftPanel"
android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:maxWidth="400dp"
/>
<fragment android:name="com.myapp.FragmentFilterPanel"
android:id="@+id/right_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
/>
</androidx.drawerlayout.widget.DrawerLayout>
<FrameLayout android:id="@+id/cluster_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="20dp"/>
<FrameLayout android:id="@+id/cluster_event_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="20dp"/>
<FrameLayout android:id="@+id/create_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="20dp"/>
以及下面的片段布局。
片段被加载到活动布局的“fragment_container”节点中。
<View android:id="@+id/backgroundColor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_light_background"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/commentFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="4dp"
android:layout_marginRight="16dp"
android:background="@color/app_light_background" >
<LinearLayout
android:id="@+id/textBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom|end"
android:measureWithLargestChild="true"
android:orientation="horizontal">
<ImageView
android:id="@+id/attachButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:elevation="1dp"
android:paddingStart="1dp"
android:paddingEnd="10dp"
android:contentDescription="Attach Picture"
app:srcCompat="@android:drawable/ic_menu_camera" />
<EditText
android:id="@+id/commentBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_weight="1"
android:ems="10"
android:hint="Comment"
android:inputType="text|textCapSentences|textMultiLine"
android:maxHeight="70dp"
android:autofillHints=""
android:textColor="@color/app_light_primary_text" />
<ImageView
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:clickable="true"
android:focusable="true"
android:paddingStart="24dp"
android:paddingTop="8dp"
android:paddingEnd="8dp"
android:paddingBottom="8dp"
android:contentDescription="Post Comment"
android:tint="@color/app_light_primary_frame"
android:src="@drawable/ic_send_grey600_36dp" />
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/commentFrame"
android:clickable="true"
android:focusable="true"
android:gravity="center_horizontal"
android:orientation="vertical">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/commentRefresh"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/commentList"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/app_light_background"
android:clickable="true"
android:focusable="true" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="@dimen/shadow_height"
android:layout_above="@+id/commentFrame"
android:background="@drawable/above_shadow" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/toolbarThemeFakeDark">
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<View android:id="@+id/backPart"
android:layout_width="match_parent"
android:layout_height="100dip"
android:clickable="true"
android:focusable="true"
android:visibility="gone" />
<View android:id="@+id/dragPart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:layout_below="@+id/backPart"
android:layout_alignParentStart="true" />
我的问题是片段中的“commentBox”字段。当您点击它时,虚拟键盘会出现在片段内容的下半部分的顶部,而不是向上推动内容。因此,您在键入时看不到文本字段。
几天来,我一直在搜索和尝试建议,例如使用“android:windowSoftInputMode=adjustPan”或一些变体。但它们都没有任何效果。
在这种情况下,是什么阻止了键盘上推 Activity 的内容?
解决方案
添加android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
到清单文件中的活动
然后添加android:fitsSystemWindows="true"
你的rootLayout(不是EditText)
推荐阅读
- asp.net - 使用证书保护 Soap Web 服务
- python-3.x - 如何分发我的 Python 3.6 应用程序以及 SqueezeTool 中的所有依赖项
- ios - Swift iOS Facebook SDK:如何分享动画 GIF?
- react-native - React-Native aws-amplify PubSub 错误
- sql - 避免 SQL 中的 case 语句过多?
- asp.net-core - ASP.NET Core 项目中声明的数据模型和架构在哪些文件中?
- r - R中密度图上的数字而不是日期
- html - 为什么这是垂直滚动而不是水平滚动?
- c# - 如何对 ConcurrentBag 进行排序?
- android - Android 辅助功能设置(对讲)焦点