Android 当根视图组为ConstraintLayout时,LinearLayout中的EditText在运行时会全屏显示
我有一个带有ViewPager2的表格布局,我在我的主要活动布局中设置了这些。在不同的布局中,我有与片段相关的布局,即主活动承载的布局 问题是,在运行时,当我单击EditText时,或者当RecyclerView中有要填充的项目时,即使没有单击EditText,EditText也会全屏显示 当RecyclerView为空且我未单击编辑文本时的布局: 单击编辑文本后: 在我将代码粘贴到这里之前。在代码中,您会注意到LinearLayout的高度是wrap_content,但这并不重要,因为对于任何高度,我都会设置它,因此会出现问题。还有,属性Android 当根视图组为ConstraintLayout时,LinearLayout中的EditText在运行时会全屏显示,android,layout,android-edittext,android-constraintlayout,Android,Layout,Android Edittext,Android Constraintlayout,我有一个带有ViewPager2的表格布局,我在我的主要活动布局中设置了这些。在不同的布局中,我有与片段相关的布局,即主活动承载的布局 问题是,在运行时,当我单击EditText时,或者当RecyclerView中有要填充的项目时,即使没有单击EditText,EditText也会全屏显示 当RecyclerView为空且我未单击编辑文本时的布局: 单击编辑文本后: 在我将代码粘贴到这里之前。在代码中,您会注意到LinearLayout的高度是wrap_content,但这并不重要,因为对于
app:layout_constrainedHeight
或者它的任何变化都不能解决问题。但是,如果根视图组是RelativeLayout,那么问题就解决了
现在,代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_viewgroup_fragment_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/color_chat"
tools:context=".ChatFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_chat"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<!-- A horizontal line between the chatbox and RecyclerView -->
<View
android:layout_width="0dp"
android:layout_height="2dp"
android:background="#dfdfdf"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@id/message_interface_layout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<LinearLayout
android:id="@+id/message_interface_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:minHeight="48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@android:color/white">
<EditText
android:id="@+id/message_edittext"
android:maxLines="5"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:hint="@string/hint_edittext_chat"
android:background="@android:color/transparent"
/>
<Button
android:id="@+id/send_message_button"
android:text="@string/chat_send_message"
android:textSize="14sp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_width="64dp"
android:layout_height="48dp"
android:gravity="center"
android:layout_gravity="bottom" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
试试这个
我想这可能会对你有帮助
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_viewgroup_fragment_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#fff"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_chat"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- A horizontal line between the chatbox and RecyclerView -->
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="2dp"
android:background="#dfdfdf"
app:layout_constraintBottom_toTopOf="@+id/message_edittext"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<EditText
android:id="@+id/message_edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dp"
android:minHeight="64dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:hint="message "
android:inputType="textMultiLine"
android:maxLines="5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/send_message_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/send_message_button" />
<Button
android:id="@+id/send_message_button"
android:layout_width="64dp"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="send message"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
试试这个
我想这可能会对你有帮助
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_viewgroup_fragment_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#fff"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_chat"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- A horizontal line between the chatbox and RecyclerView -->
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="2dp"
android:background="#dfdfdf"
app:layout_constraintBottom_toTopOf="@+id/message_edittext"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<EditText
android:id="@+id/message_edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dp"
android:minHeight="64dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:hint="message "
android:inputType="textMultiLine"
android:maxLines="5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/send_message_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/send_message_button" />
<Button
android:id="@+id/send_message_button"
android:layout_width="64dp"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="send message"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
适用于任何其他有屏幕大小调整问题的人。我找遍了stackoverflow,没有找到任何解决方案。我看到到处都可以使用带有“adjustPan”或“adjustResize”或任何变体的窗口软模式 问题是我使用的应用程序主题没有ActionBar,我实现了自己的工具栏
解决方案是使用AppCompat或MaterialComponents提供的默认应用程序主题。适用于任何有屏幕大小调整问题的其他人。我找遍了stackoverflow,没有找到任何解决方案。我看到到处都可以使用带有“adjustPan”或“adjustResize”或任何变体的窗口软模式 问题是我使用的应用程序主题没有ActionBar,我实现了自己的工具栏
解决方案是使用AppCompat或MaterialComponents提供的默认应用程序主题。线性布局宽度是
android:layout\u width=“0dp”
更改为换行_content@ShaluTD这与问题无关在编辑文本上设置一个静态宽度,比如Android:layout\u width=100dpLInear layout width是Android:layout\u width=“0dp”
更改为换行_content@ShaluTD这与问题无关在编辑文本上设置一个静态宽度,如Android:layout_width=100dp