【问题标题】:Android Studio does not show layout preview(no error occurs also)Android Studio 不显示布局预览(也没有错误发生)
【发布时间】:2021-12-04 18:41:59
【问题描述】:

Android Studio 不显示布局的预览。没有显示错误或警告。我已经尝试过这个解决方案Invalidate Caches/ Restart.

XML 文件:

<?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"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context=".MainActivity">
    
    <ListView
        android:id="@+id/peripherals_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <TextView android:id="@+id/peripheral_list_empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/peripheral_list_empty"/>

</RelativeLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

    标签: android xml android-studio android-layout


    【解决方案1】:
         <?xml version="1.0" encoding="utf-8"?>
         <RelativeLayout 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=".MainActivity">
    
             <TextView
                 android:id="@+id/txt"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="Hello World!"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintLeft_toLeftOf="parent"
                 app:layout_constraintRight_toRightOf="parent"
                 app:layout_constraintTop_toTopOf="parent" />
    
    
          <ListView
                android:id="@+id/list"
                android:layout_width="wrap_content"
                android:layout_below="@+id/txt"
                android:layout_height="wrap_content"/>
    
       </RelativeLayout>
    

    【讨论】:

    • 如果您认为您可以回答这个问题,请在您的回答中提供解释。
    【解决方案2】:

    如果系统 UI 开启 Listview 将不会显示。寻找带有眼睛的图标并取消标记显示系统 UI

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 2022-09-22
    • 1970-01-01
    相关资源
    最近更新 更多