Я сейчас бьюсь над этой проблемой уже несколько часов. поэтому у меня есть действие с панелью инструментов и полосой прокрутки внутри его макета. вот макет
с идентификатором контейнераInputBox — это контейнер для многих групп просмотра с EditText внутри него (найдите прикрепленное изображение). представление прокрутки прокручивается, когда отображается программная клавиатура, однако отображаются не все группы просмотра, некоторые из них все еще перекрываются клавиатурой.
здесь мой класс/активность
package com.jasatirta2.sisda
import android.app.DatePickerDialog
import android.app.TimePickerDialog
import android.content.Context
import android.graphics.Rect
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.ScrollView
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.github.mikephil.charting.data.Entry
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.jasatirta2.sisda.helpers.CustomAlertDialog
import com.jasatirta2.sisda.model.DataPeriodic
import com.jasatirta2.sisda.model.InputData
import com.jasatirta2.sisda.model.ShareData
import okhttp3.Call
import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale
class OperationInputData : AppCompatActivity() {
val client = OkHttpClient()
var token: String? = ""
val dataPeriodicUrl: String = "https://reference.jasatirta2.id/dataperiodic"
var locationId = 0
var locationName: String? = ""
var date = SimpleDateFormat("yyyy-MM-dd").format(Date())
var time = SimpleDateFormat("HH:mm").format(Date())
val calendar = Calendar.getInstance()
private var selectedYear = calendar.get(Calendar.YEAR)
private var selectedMonth = calendar.get(Calendar.MONTH)
private var selectedDay = calendar.get(Calendar.DAY_OF_MONTH)
private var hour = calendar.get(Calendar.HOUR_OF_DAY)
private var minute = calendar.get(Calendar.MINUTE)
lateinit var periodics: List
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_operation_input_data)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
val sharedPref = getSharedPreferences(getString(R.string.sisda_token_data), Context.MODE_PRIVATE)
token = sharedPref.getString("access_token", "")
locationName = intent.getStringExtra("location_name")
locationId = intent.getIntExtra("location_id", 0)
val toolbar = findViewById(R.id.toolbar).apply {
subtitle = locationName
}
setSupportActionBar(toolbar);
getSupportActionBar()!!.setDisplayHomeAsUpEnabled(true);
getSupportActionBar()!!.setDisplayShowHomeEnabled(true);
val etDate = findViewById(R.id.etDate)
etDate.text = date
etDate.setOnClickListener {
val datePickerDialog = DatePickerDialog(
this,
{ _, selectedYear, selectedMonth, selectedDay ->
this.selectedYear = selectedYear
this.selectedMonth = selectedMonth
this.selectedDay = selectedDay
date = String.format(
Locale.getDefault(),
"%04d-%02d-%02d",
selectedYear,
selectedMonth + 1,
selectedDay
)
etDate.setText(date)
},
selectedYear,
selectedMonth,
selectedDay
)
datePickerDialog.show()
}
val etTime = findViewById(R.id.etTime)
etTime.text = time
etTime.setOnClickListener {
val calendar = Calendar.getInstance()
val timePickerDialog = TimePickerDialog(
this,
{ _, selectedHour, selectedMinute ->
time = String.format(
Locale.getDefault(),
"%02d:%02d",
selectedHour,
selectedMinute
)
etTime.text = time;
},
hour,
minute,
true
)
timePickerDialog.show()
}
val scrollView = findViewById(R.id.sv)
scrollView.viewTreeObserver.addOnGlobalLayoutListener {
val rect = Rect()
scrollView.getWindowVisibleDisplayFrame(rect)
val screenHeight = scrollView.rootView.height
val keypadHeight = screenHeight - rect.bottom
if (keypadHeight > screenHeight * 0.15) {
// Keyboard is opened
scrollView.post {
val mainLayout = findViewById(R.id.main)
scrollView.smoothScrollTo(0, mainLayout.bottom)
}
}
}
getData()
}
fun getData(){
val url = "$dataPeriodicUrl/$locationId?token=$token"
Log.d("SISDA_DEBUG", url)
val request = Request.Builder()
.url(url)
.build()
val loading = LoadingOverlayDialog(this@OperationInputData).show()
client.newCall(request).enqueue(object: Callback {
override fun onFailure(call: Call, e: IOException) {
Handler(Looper.getMainLooper()).post {
CustomAlertDialog(this@OperationInputData, "Terjadi kesalahan pada server", "Gagal")
.show()
}
}
override fun onResponse(call: Call, response: Response) {
if(!response.isSuccessful){
Handler(Looper.getMainLooper()).post {
CustomAlertDialog(this@OperationInputData, "Terjadi kesalahan pada server", "Gagal")
.show()
}
}else{
val responseBody = response.body!!.string()
val dataListType = object: TypeToken() {}.type
periodics = Gson().fromJson(responseBody, dataListType)
val container = findViewById(R.id.containerInputBox)
for(data in periodics){
val view = renderBox(container, data)
Handler(Looper.getMainLooper()).post {
container.addView(view)
}
}
}
Handler(Looper.getMainLooper()).post {
loading.hide()
}
}
})
}
// HERE THE CODE TO ADD viewgroup into `containerInputBox`
fun renderBox(parent: ViewGroup, data: DataPeriodic): View{
val view = LayoutInflater.from(parent.context).inflate(R.layout.operation_input_data_box, parent, false)
// later i will bind the data to the textview/edittext
return view
}
}
в моем манифесте.xml я уже добавил android:windowSoftInputMode="adjustResize", а также попробовал другие значения, но все равно не работает должным образом. как мне решить эту проблему?
Я сейчас бьюсь над этой проблемой уже несколько часов. поэтому у меня есть действие с панелью инструментов и полосой прокрутки внутри его макета. вот макет [code]
[/code] [code]LinearLayout[/code] с идентификатором контейнераInputBox — это контейнер для многих групп просмотра с EditText внутри него (найдите прикрепленное изображение). представление прокрутки прокручивается, когда отображается программная клавиатура, однако отображаются не все группы просмотра, некоторые из них все еще перекрываются клавиатурой. здесь мой класс/активность [code]package com.jasatirta2.sisda
class OperationInputData : AppCompatActivity() { val client = OkHttpClient() var token: String? = "" val dataPeriodicUrl: String = "https://reference.jasatirta2.id/dataperiodic" var locationId = 0 var locationName: String? = "" var date = SimpleDateFormat("yyyy-MM-dd").format(Date()) var time = SimpleDateFormat("HH:mm").format(Date()) val calendar = Calendar.getInstance() private var selectedYear = calendar.get(Calendar.YEAR) private var selectedMonth = calendar.get(Calendar.MONTH) private var selectedDay = calendar.get(Calendar.DAY_OF_MONTH) private var hour = calendar.get(Calendar.HOUR_OF_DAY) private var minute = calendar.get(Calendar.MINUTE) lateinit var periodics: List
scrollView.viewTreeObserver.addOnGlobalLayoutListener { val rect = Rect() scrollView.getWindowVisibleDisplayFrame(rect) val screenHeight = scrollView.rootView.height val keypadHeight = screenHeight - rect.bottom
if (keypadHeight > screenHeight * 0.15) { // Keyboard is opened scrollView.post { val mainLayout = findViewById(R.id.main) scrollView.smoothScrollTo(0, mainLayout.bottom) } } }
getData() }
fun getData(){ val url = "$dataPeriodicUrl/$locationId?token=$token" Log.d("SISDA_DEBUG", url) val request = Request.Builder() .url(url) .build()
val loading = LoadingOverlayDialog(this@OperationInputData).show()
// HERE THE CODE TO ADD viewgroup into `containerInputBox` fun renderBox(parent: ViewGroup, data: DataPeriodic): View{ val view = LayoutInflater.from(parent.context).inflate(R.layout.operation_input_data_box, parent, false) // later i will bind the data to the textview/edittext return view } } [/code] в моем манифесте.xml я уже добавил android:windowSoftInputMode="adjustResize", а также попробовал другие значения, но все равно не работает должным образом. как мне решить эту проблему? [img]https://i.sstatic.net/yrpSRB20.jpg[/img]