Created
June 13, 2018 17:59
-
-
Save e16din/97ee06eeb72a4161971f24dbf3ae81c1 to your computer and use it in GitHub Desktop.
Когда открывается клавиатура, скроллить макет диалога в самый низ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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