簡體   English   中英

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

[英]Can't see elements layout android studio in activity_main.xml

我從 android studio 開始,我看不到元素(按鈕,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 This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints

您可以通過修復styles.xml 文件來解決此問題。

找到styles.xml

然后你只需要在這段代碼中添加 Base :

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

最終代碼:

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

如果你有同樣的錯誤,因為這頁,你應該改變com.android.support:appcompat-v7:28.0.0-alpha3com.android.support:appcompat-v7:28.0.0-alpha1build.gradle(Module: app)並單擊文件 -> 使緩存無效/重新啟動。 現在一切正常。

在此處輸入圖片說明

當然,您需要訪問互聯網才能下載com.android.support:appcompat-v7:28.0.0-alpha1

解決這個問題:

  1. 刪除 API 版本 27 和 28。工具-->SDK 管理器取消選中版本 27 和 28
  2. 卸載安卓工作室
  3. 重新安裝android studio到26版本,問題解決

在此處輸入圖片說明

用這個內部應用程序gradle替換

在此處輸入圖片說明

1)嘗試使用頂部構建菜單中的選項清理項目

2) 嘗試通過選擇 File 菜單中的選項使 Android Studio 無效並重新啟動

3)嘗試通過選擇頂部構建菜單中的選項來重建項目

我已經解決了這個問題:

我的 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')

}

我已將所有帶有“alpha3”的行更改為“alpha1”。 謝謝@hossein-seifi

在 Values.(res>>Values>>Styles.xml) 中找到Styles.xml改變這個

添加“基地”

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

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

然后清理並構建項目。 您可以從構建菜單中執行這兩項操作。

它對我有用。

我有一個類似的問題(Android Studio 4.1.1)。 我不僅看不到設計視圖上的元素,而且我無法將任何新元素拖到布局或組件樹中 - 當我嘗試拖放它們時沒有任何反應。 (它們似乎拖着,但當我放下它們時它們就消失了。)這只是一個項目中的一項活動 - 其他活動似乎很好。

這里沒有一個解決方案對我有用。

最后,我復制並粘貼了現有元素的代碼,驗證它是否出現在組件樹中,然后進行了強制刷新布局。 (我確定我已經嘗試過這最后一步但沒有成功。)

元素重新出現,我能夠再次拖放新元素。

強制刷新布局選項

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM