In recyclerview, I am using item view which has an ImageView and an EditText(caption below the image). Until I updated targetSdkVersion to 30, everything worked well. And then I changed nothing but the targetSdkVersion from '29' to '30', and now adjustResize won't work as expected.
Wierd thing is that this occurs upon the image's size. When the Image is small and is fully shown, the RecyclerView does scroll up to show the focused EditText. Though when the image is partially visible, the focused EditText hides behind the IME.
I have tested with below code.
MainActivity and Adapter:
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 not working with a partially visible image(API 30 Emulator):
If anybody knows how to solve this problem, plz help me.