Android Studio space 在我的微调器和页面标题之间
Android Studio space between my spinner and page title
我最近开始使用 Android Studio,因为我想为我的 Android 设备创建一个应用程序。
我选择底部导航 activity 作为模板并添加了一个微调器。我将微调器放在页面标题下尽可能高的位置,但是当我通过 Android 10 phone 上的调试启动应用程序时,微调器和我的微调器之间有一个大的白色 space我的页面标题。但是预览里没有。
如果重要的话,我有小米 Redmi Note 8T Global。
我的片段代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.myfragment.MyFragment"
tools:layout_editor_absoluteY="81dp">
<Spinner
android:id="@+id/myspinner"
android:layout_width="391dp"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="SpeakableTextPresentCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>
在 android 工作室中预览
它在应用程序中的样子
提前致谢
尝试从您的 constraintLayout 中删除 tools:layout_editor_absoluteY="81dp"
。
绝对布局允许您指定其子项的确切位置(x/y 坐标)。
从您的代码中删除以下行以解决问题::
工具:layout_editor_absoluteY="81dp"
应用程序:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.0"
试试这个来解决问题::
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/myspinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:spinnerMode="dropdown"
android:entries="@array/spinnnerItem"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="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:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<Spinner
android:id="@+id/myspinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
而实际的区别是,Activity 的主题与 XML 预览不同。一个主题有 ActionBar
- 而另一个没有(有些 .NoActionBar
主题)。因此,您可能希望在 AndroidManifest.xml
中应用相同的主题,您将其用于 XML 预览。
我查看了我的 MainActivity.xml 文件,发现有一行代码:android:paddingTop="?attr/actionBarSize">
将其删除,不再有白条!
感谢 franvillacis,是他让我重新审视了我的 MainActivity.xml
我最近开始使用 Android Studio,因为我想为我的 Android 设备创建一个应用程序。
我选择底部导航 activity 作为模板并添加了一个微调器。我将微调器放在页面标题下尽可能高的位置,但是当我通过 Android 10 phone 上的调试启动应用程序时,微调器和我的微调器之间有一个大的白色 space我的页面标题。但是预览里没有。
如果重要的话,我有小米 Redmi Note 8T Global。
我的片段代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.myfragment.MyFragment"
tools:layout_editor_absoluteY="81dp">
<Spinner
android:id="@+id/myspinner"
android:layout_width="391dp"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="SpeakableTextPresentCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>
在 android 工作室中预览
它在应用程序中的样子
提前致谢
尝试从您的 constraintLayout 中删除 tools:layout_editor_absoluteY="81dp"
。
绝对布局允许您指定其子项的确切位置(x/y 坐标)。
从您的代码中删除以下行以解决问题::
工具:layout_editor_absoluteY="81dp"
应用程序:layout_constraintBottom_toBottomOf="parent" app:layout_constraintVertical_bias="0.0"
试试这个来解决问题::
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/myspinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:spinnerMode="dropdown"
android:entries="@array/spinnnerItem"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="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:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<Spinner
android:id="@+id/myspinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
而实际的区别是,Activity 的主题与 XML 预览不同。一个主题有 ActionBar
- 而另一个没有(有些 .NoActionBar
主题)。因此,您可能希望在 AndroidManifest.xml
中应用相同的主题,您将其用于 XML 预览。
我查看了我的 MainActivity.xml 文件,发现有一行代码:android:paddingTop="?attr/actionBarSize">
将其删除,不再有白条!
感谢 franvillacis,是他让我重新审视了我的 MainActivity.xml