好的,大家都知道要隐藏你需要实现的键盘:
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
但这里最重要的是当用户触摸或选择任何其他不是EditText
软键盘或软键盘的地方时如何隐藏键盘?
我试图onTouchEvent()
在我的父母Activity
身上使用,但这只有在用户触摸任何其他视图以外且没有滚动视图时才有效.
我尝试实现触摸,单击,集中监听器而没有任何成功.
我甚至尝试实现自己的scrollview来拦截触摸事件,但我只能获取事件的坐标而不是点击的视图.
有没有一种标准的方法来做到这一点?在iPhone中它真的很容易.
我的表格大约有12/13个字段.我Scrollview
在约束布局中使用了一个内部.下面是XML布局的层次结构.问题是,它不会滚动到底部而是仅滚动到前10个初始视图.最后3个字段被隐藏,因为视图不再滚动.
父母布局
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_register"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical">
<!-- Textview and a button -->
<ScrollView
android:id="@+id/scrollView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:overScrollMode="never"
android:scrollbars="none"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Child Views (12/13 views of the fields)-->
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) android constraints scrollview android-layout android-constraintlayout
该计划中的一些问题.我不知道是什么问题.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.bharathi.r_box.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AlertDialog.AppCompat.Light" >
</android.support.v7.widget.Toolbar>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/activity_horizontal_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释这个问题是什么?
我正在制作动画,如果用户点击它,它将会增长视图.基本上,它是一张卡片,当点击它时,它会显示底部内容.为此,我正在扩展这样的动画:
Val collapseAnimation = object : Animation() {
override fun applyTransformation(interpolatedTime: Float, t: Transformation?) {
val interpolatedInverted = 1 - interpolatedTime
val headerLp = headerImage.layoutParams
headerLp.width = ...
headerImage.layoutParams = headerLp
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我需要将XML中定义的视图(wrap_content)的高度设置为0dp.基本上,我想长大一个从0dp到wrap_content的视图,为此我需要知道wrap_content大小是什么.
如何在不对视图大小进行硬编码的情况下以最有效的方式实现这一目标?