Skip to content

Instantly share code, notes, and snippets.

@e16din
Created June 13, 2018 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e16din/97ee06eeb72a4161971f24dbf3ae81c1 to your computer and use it in GitHub Desktop.
Save e16din/97ee06eeb72a4161971f24dbf3ae81c1 to your computer and use it in GitHub Desktop.
Когда открывается клавиатура, скроллить макет диалога в самый низ
View vDialogContent = inflateView(getActivity(), R.layout.w_dialog);
ScrollView vScrollableContainer = vDialogContent.findViewById(R.id.vScrollableContainer);
View view = ResizableFrameLayout.wrap(vDialogContent, () ->
vScrollableContainer.post(() -> {
View vContent = vScrollableContainer.getChildAt(0);
vScrollableContainer.scrollTo(0, vContent.getMeasuredHeight());
}),
null);
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
open class ResizableFrameLayout : FrameLayout {
companion object {
@JvmStatic
fun wrap(view: View,
onIncreaseHeight: Runnable? = null,
onDecreaseHeight: Runnable? = null): View {
val vResizableContainer = object : ResizableFrameLayout(view.context) {
override fun onIncreaseHeight() {
onIncreaseHeight?.run()
}
override fun onDecreaseHeight() {
onDecreaseHeight?.run()
}
}
vResizableContainer.addView(view)
return vResizableContainer
}
}
@JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
super(context, attrs, defStyleAttr)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) :
super(context, attrs, defStyleAttr, defStyleRes)
open fun onDecreaseHeight() {}
open fun onIncreaseHeight() {}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val proposedHeight = View.MeasureSpec.getSize(heightMeasureSpec)
val actualHeight = height
if (actualHeight > proposedHeight) {
onDecreaseHeight()
} else if (actualHeight < proposedHeight) {
onIncreaseHeight()
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment