android - 如何防止editText与recyclerView重叠?
问题描述
问题是软键盘出现的时候,和recyclerView重叠。但我希望我的软键盘只需将回收器推到顶部,在键盘上方,就像windowSoftInputMode="adjustPan"一样。但是 adjustPan 不是选项,因为我需要我的工具栏。
我已经尝试过adjustResize,但没有运气。
主要活动布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<include
layout="@layout/toolbar_layout"
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/recyc"
app:layout_constraintBottom_toTopOf="@+id/message_edit_text"
app:layout_constraintTop_toBottomOf="@+id/toolbar_layout"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/message_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textShortMessage"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
适配器项目布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
这是我的MainActivity代码,只有 onCreate 方法
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
recyc.layoutManager = LinearLayoutManager(this)
val adapter = MyAdapter(
arrayOf("sd","sd2","sd2","sd2","sd2","s2d","s2d","sd",
"sd2","s2d","s2d","sd5","s8d","67sd","s76d")
)
recyc.adapter = adapter
}
这是我的适配器类
class MyAdapter(private val myDataset: Array<String>) :
RecyclerView.Adapter<MyAdapter.MyViewHolder>() {
class MyViewHolder(val view: View) :
RecyclerView.ViewHolder(view)
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): MyAdapter.MyViewHolder {
val textView = LayoutInflater.from(parent.context)
.inflate(R.layout.container, parent, false)
return MyViewHolder(textView)
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int)
{ holder.itemView.textView.text = myDataset[position] }
override fun getItemCount() = myDataset.size
}
解决方案
推荐阅读
- python - Python 如何遍历包含变量的字符串列表?
- azure-cognitive-search - Azure 搜索 - 线程池中没有足够的空闲线程来完成操作
- javascript - 使用具有 n 深度的递归添加价格总和的类方法
- vue.js - 如何增加 Vuetify v-slider 的 nob 周围的可点击区域?
- vuex - 如何从 nuxtjs 商店访问路由器?
- jenkins - naginator-plugin(失败时重试)和'Tigger parameterized build on other projects'的用法
- reactjs - 成功获取的 Firestore 数据未呈现(React)
- python - 使用 SQLAlchemy 检查我的 pandas DF 是否“适合”到数据库表中
- c# - 即使内容和代码最少,扩展 viewcell 的自定义控件也会引发 System.InvalidCastException
- sampling - R中随机变量的生成