显示键盘时如何调整布局
How resize layout when keyboard shown
大家早上好,我在显示键盘时调整布局大小有一个小问题。
在清单中,我有 adjustResize,我也尝试使用 adjustPan,但我在滚动 recyclerview 时遇到问题。
我的布局代码是:
<LinearLayout
android:id="@+id/layoutGeneralHome"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragments.fragment_home">
<LinearLayout
android:id="@+id/layoutRecycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9">
<android.support.v7.widget.RecyclerView
android:id="@+id/listChatGeneral"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.10"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:orientation="vertical">
<EditText
android:id="@+id/edtMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Scrivi messaggio"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25">
<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="INVIA"
android:textSize="18sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
谢谢谁能帮助我
这是我在我的应用程序中的视图,它工作正常,试试这个:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:mContext="hvasoftware.com.tudiendanhngon.view.activities.CommentActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvComment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone"
ads:layout_constraintBottom_toTopOf="@+id/viewComment"
ads:layout_constraintTop_toBottomOf="parent" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateTint="@color/colorAccent"
android:visibility="visible"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintLeft_toLeftOf="parent"
ads:layout_constraintRight_toRightOf="parent"
ads:layout_constraintTop_toTopOf="parent"
tools:targetApi="lollipop" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/viewComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
>
<EditText
android:id="@+id/edtComment"
android:layout_width="match_parent"
android:layout_height="50dp"
android:fontFamily="sans-serif-light"
android:inputType="textCapSentences"
android:paddingLeft="9dp"
android:paddingRight="50dp"
android:textColor="@color/colorAccent"
android:textSize="14sp"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintLeft_toLeftOf="parent"
ads:layout_constraintRight_toLeftOf="@+id/ibUpComment" />
<ImageButton
android:id="@+id/ibUpComment"
android:layout_width="23dp"
android:layout_height="26dp"
ads:layout_constraintBottom_toBottomOf="@id/edtComment"
ads:layout_constraintRight_toRightOf="parent"
ads:layout_constraintTop_toTopOf="@+id/edtComment" />
<ProgressBar
android:id="@+id/progressBarUpload"
style="?android:attr/progressBarStyle"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_centerInParent="true"
android:layout_marginEnd="16dp"
android:indeterminate="true"
android:indeterminateTint="@color/colorAccent"
android:visibility="gone"
ads:layout_constraintBottom_toBottomOf="@id/edtComment"
ads:layout_constraintRight_toRightOf="parent"
ads:layout_constraintTop_toTopOf="@+id/edtComment"
tools:targetApi="lollipop" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
无需添加scrollview,使用Relative layout U即可实现你想要的Screen。
我添加了如下所示的相对布局和代码。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/listChatGeneral"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/llSendView" />
<LinearLayout
android:id="@+id/llSendView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:orientation="vertical">
<EditText
android:id="@+id/edtMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Scrivi messaggio" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25">
<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="INVIA"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
大家早上好,我在显示键盘时调整布局大小有一个小问题。
在清单中,我有 adjustResize,我也尝试使用 adjustPan,但我在滚动 recyclerview 时遇到问题。
我的布局代码是:
<LinearLayout
android:id="@+id/layoutGeneralHome"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragments.fragment_home">
<LinearLayout
android:id="@+id/layoutRecycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9">
<android.support.v7.widget.RecyclerView
android:id="@+id/listChatGeneral"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.10"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:orientation="vertical">
<EditText
android:id="@+id/edtMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Scrivi messaggio"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25">
<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="INVIA"
android:textSize="18sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
谢谢谁能帮助我
这是我在我的应用程序中的视图,它工作正常,试试这个:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:mContext="hvasoftware.com.tudiendanhngon.view.activities.CommentActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvComment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone"
ads:layout_constraintBottom_toTopOf="@+id/viewComment"
ads:layout_constraintTop_toBottomOf="parent" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateTint="@color/colorAccent"
android:visibility="visible"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintLeft_toLeftOf="parent"
ads:layout_constraintRight_toRightOf="parent"
ads:layout_constraintTop_toTopOf="parent"
tools:targetApi="lollipop" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/viewComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
>
<EditText
android:id="@+id/edtComment"
android:layout_width="match_parent"
android:layout_height="50dp"
android:fontFamily="sans-serif-light"
android:inputType="textCapSentences"
android:paddingLeft="9dp"
android:paddingRight="50dp"
android:textColor="@color/colorAccent"
android:textSize="14sp"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintLeft_toLeftOf="parent"
ads:layout_constraintRight_toLeftOf="@+id/ibUpComment" />
<ImageButton
android:id="@+id/ibUpComment"
android:layout_width="23dp"
android:layout_height="26dp"
ads:layout_constraintBottom_toBottomOf="@id/edtComment"
ads:layout_constraintRight_toRightOf="parent"
ads:layout_constraintTop_toTopOf="@+id/edtComment" />
<ProgressBar
android:id="@+id/progressBarUpload"
style="?android:attr/progressBarStyle"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_centerInParent="true"
android:layout_marginEnd="16dp"
android:indeterminate="true"
android:indeterminateTint="@color/colorAccent"
android:visibility="gone"
ads:layout_constraintBottom_toBottomOf="@id/edtComment"
ads:layout_constraintRight_toRightOf="parent"
ads:layout_constraintTop_toTopOf="@+id/edtComment"
tools:targetApi="lollipop" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
无需添加scrollview,使用Relative layout U即可实现你想要的Screen。 我添加了如下所示的相对布局和代码。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/listChatGeneral"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/llSendView" />
<LinearLayout
android:id="@+id/llSendView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:orientation="vertical">
<EditText
android:id="@+id/edtMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Scrivi messaggio" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25">
<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="INVIA"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>