gpt4 book ai didi

Android studio 3.1.4 工具栏卡在角落

转载 作者:搜寻专家 更新时间:2023-11-01 08:20:07 26 4
gpt4 key购买 nike

这很难解释——但我尝试在我的项目中添加的所有工具栏似乎都卡在了角落里。

我做了一个测试布局来展示清楚:测试蓝图工具栏

Test blueprint toolbar

点击图片查看大图。

这是 xml:

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="1000dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</LinearLayout>

我尝试过使用不同的布局。也无法拖动工具栏来调整它的大小。

这是我的真实布局 Real layout

代码

<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/auth_request_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AuthRequestActivity">

<android.support.v7.widget.Toolbar
android:id="@+id/activity_auth_request_toolbar"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentTop="true"
android:background="@color/somecompanycolor"
android:minHeight="@dimen/toolbar_height"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<fragment
android:id="@+id/activity_auth_request_fragment"
android:name="someexternalsdk"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/activity_auth_request_toolbar" />

</android.support.constraint.ConstraintLayout>

我设置工具栏的代码:

mToolbar = findViewById(R.id.activity_auth_request_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Request");

有关更多信息,我的目标是 28.0.0-rc02,最大 sdk 版本 28,最小 15。

有人知道我做错了什么吗?

最佳答案

编辑 1

这似乎是 Android 28.0.0-rc02 上的错误

build.gradle 中降级 27 并依赖 27.1.1 将解决此问题

原始答案

您正在使用 ConstraintLayout 但您的 View 不受约束

当我们没有定义任何约束时,这是 android studio 通常向我们显示的警告

This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime

像这样定义工具栏的约束

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main2Activity">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
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" />
</android.support.constraint.ConstraintLayout>

关于Android studio 3.1.4 工具栏卡在角落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52463950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com