问题描述
在 recyclerview 中,我使用的是具有 ImageView 和 EditText(图片下方的标题)的项目视图。 直到我将 targetSdkVersion 更新为 30,一切都运行良好。然后我只将 targetSdkVersion 从“29”更改为“30”,而现在 adjustResize 无法按预期工作。
奇怪的是,这发生在图像的大小上。 当图像很小并完全显示时,RecyclerView 确实向上滚动以显示聚焦的 EditText。 虽然当图像部分可见时,聚焦的 EditText 隐藏在 IME 后面。
我已经使用以下代码进行了测试。
MainActivity 和适配器:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val myAdapter = MyAdapter()
val recyclerView = findViewById<RecyclerView>(R.id.recycler_view)
recyclerView.apply {
adapter = myAdapter
layoutManager = linearlayoutmanager(context)
}
myAdapter.items.addAll(listof(true,true,true))
myAdapter.notifyDataSetChanged()
}
}
class MyAdapter: RecyclerView.Adapter<MyAdapter.MyViewHolder>(){
class MyViewHolder(view: View): RecyclerView.ViewHolder(view)
val items = mutablelistof<Boolean>()
override fun onCreateViewHolder(parent: ViewGroup,viewType: Int): MyViewHolder {
val view = LayoutInflater.from(parent.context).inflate(
R.layout.item_edit_text,parent,false
)
return MyViewHolder(view)
}
override fun getItemCount(): Int = items.size
override fun onBindViewHolder(holder: MyViewHolder,position: Int) {}
}
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:background="@color/white">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
item_edit_text.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="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/item_image"
android:layout_width="match_parent"
android:layout_height="500dp"
android:src="@color/purple_200" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/item_image_caption_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="abcd test" />
</LinearLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testapplication">
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.TestApplication">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
AdjustResize 不适用于部分可见的图像(API 30 模拟器):
如果有人知道如何解决这个问题,请帮助我。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)