【问题标题】:Android Studio 1.5.1 Layout File Design View not updatingAndroid Studio 1.5.1 布局文件设计视图未更新
【发布时间】:2016-02-27 18:36:31
【问题描述】:

我是第一次使用 Android Studio 1.5.1。问题是,当我通过其 XML 代码或从其属性窗口更改 TextView 控件的值时,它不会在预览(设计视图)上更改。但是,当我测试应用程序时,它会显示更新后的值。 这里是截图... Value of TextView is changed in Properties window, but not updated on Layout Preview

我尝试了几件事,例如清理、重建、使缓存无效/重新启动。我的 SDK 和 Android Studio 也更新了...

编辑 2016 年 2 月 28 日

我对这个问题有一个奇怪的解决方案。实际上,我试图在 API 级别 23 的布局设计中呈现我的活动。我首先打开了 activity_main.xml 文件并注释掉以下 xml 代码:-

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

并注释掉这段代码:-

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

然后打开MainActivity.java文件并注释掉以下代码:-

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

它解决了我的两个问题。现在布局文件 (content_main.xml) 的设计视图正在更新,因为我在 xml 代码中对其进行了更改。并且设计视图也为 API 级别 23 成功渲染。以前,它正在为 API 级别 23 创建渲染问题。至于渲染问题,我以某种方式理解它。但是为什么布局文件的设计视图现在正在更新?

【问题讨论】:

  • 没有。应用程序运行良好。

标签: android android-studio preview


【解决方案1】:

您可以使用预览来进行 xml 更改。 android studio 提供 preview 屏幕来查看 xml 更改。它会立即显示更改,因此您也可以在进行更改时查看,并且那里还有刷新按钮,以防您因任何技术错误而无法看到更改,只需按 refresh 按钮即可刷新 xml 设计.

【讨论】:

    猜你喜欢
    • 2020-07-05
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多