无法在activity_main.xml中看到元素布局android studio

时间:2018-06-17 13:50:22

标签: android android-studio

我从android studio开始,我无法看到元素(Buttons,TextView,..),我在activity_main.xml页面的“设计”页面中拖放。这些元素存在于我的XML文件中,当我在设备上运行我的应用程序时,我可以看到它们,但我不知道如何在“设计和蓝图”中找到它们。页。

感谢您的帮助。

这是我的xml代码:

<?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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:layout_editor_absoluteY="25dp">

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/title_home"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="1dp"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:menu="@menu/navigation" />

    <Button
        android:id="@+id/button"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:text="ClickMe"
        tools:layout_editor_absoluteX="-73dp"
        tools:layout_editor_absoluteY="29dp" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="20dp" />


</android.support.constraint.ConstraintLayout>

我的画布完全是空的。

编辑:

我有2个错误:

  • 渲染问题:Failed to find style 'bottomNavigationStyle' in current theme Tip: Try to refresh the layout.

  • ConstraintLayout中缺少约束: This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints

8 个答案:

答案 0 :(得分:17)

您可以通过修复styles.xml文件来解决此问题。

find the styles.xml

然后您只需要在此代码中添加Base:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

最终代码:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

答案 1 :(得分:3)

如果您遇到与此页面相同的错误,则应在com.android.support:appcompat-v7:28.0.0-alpha3中将com.android.support:appcompat-v7:28.0.0-alpha1更改为build.gradle(Module: app),然后点击文件 - &gt;使高速缓存/重新启动无效。现在一切都好。

enter image description here

当然,您需要访问互联网才能下载com.android.support:appcompat-v7:28.0.0-alpha1

答案 2 :(得分:2)

enter image description here

替换为该内部应用gradle

enter image description here

答案 3 :(得分:1)

要解决此问题:

  1. 删除API版本27和28。工具-> SDK管理器取消选中版本27和28
  2. 卸载android studio
  3. 重新安装最高版本26的android studio,问题已解决

答案 4 :(得分:0)

1)尝试使用顶部

中的构建菜单中的选项来清理项目

2)通过选择“文件”菜单中的选项

,尝试使Android Studio无效并重新启动

3)尝试通过选择顶部

中的构建菜单中的选项重建项目

答案 5 :(得分:0)

我已经解决了问题:

我的build.gradle文件:

dependencies {
 api 'com.android.support:appcompat-v7:28.0.0-alpha1'
 api 'com.android.support:design:28.0.0-alpha1'
 api 'com.android.support.constraint:constraint-layout:1.1.2'
 api 'com.android.support:support-vector-drawable:28.0.0-alpha1'
 application project(':app')
 feature project(':feature')

}

我用&#34; alpha3&#34;改变了所有的行。 by&#34; alpha1&#34;。 谢谢@ hossein-seifi

答案 6 :(得分:0)

在值中找到Styles.xml。(res >> Values >> Styles.xml)更改

添加“基本”

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to this:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

然后清理并构建项目。您都可以在构建菜单中完成这两项操作。

对我有用。

答案 7 :(得分:0)

我遇到了类似的问题(Android Studio 4.1.1)。我不仅看不到设计视图上的元素,而且我无法将任何新元素拖到布局或组件树中 - 当我尝试拖放它们时没有任何反应。 (它们看起来很拖,但当我放下它们时它们就消失了。)这只是一个项目中的一项活动 - 其他活动似乎很好。

这里的所有解决方案都不适合我。

最后,我复制并粘贴了现有元素的代码,验证它出现在组件树中,然后执行强制刷新布局。 (我确定我已经尝试过这最后一步但没有成功。)

元素重新出现,我可以再次拖放新元素。

Force Refresh Layout option

相关问题