Android Android 工作室中的自定义视图预览
Android Custom View preview in Android studio
我正在开发一个自定义视图,我希望它像下面的 Google 广告视图一样显示。我的视图不包含任何文本视图,但我仍然希望它有这样的预览。
任何人都可以支持我的解决方案吗?谢谢!!
"tools" 命名空间或许可以在这方面为您提供帮助。您可以使用以下行添加它:
xmlns:tools="http://schemas.android.com/tools"
在您的根布局中。 tools:text 之类的内容将显示在预览中,但当应用程序为 运行 时则不会。所以如下观点:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
tools:text="Preview Text" />
</RelativeLayout>
将在预览中显示 "Preview Text" 的 TextView,但它实际上是 View.GONE,并且在 运行 时没有文本。
我正在开发一个自定义视图,我希望它像下面的 Google 广告视图一样显示。我的视图不包含任何文本视图,但我仍然希望它有这样的预览。
任何人都可以支持我的解决方案吗?谢谢!!
"tools" 命名空间或许可以在这方面为您提供帮助。您可以使用以下行添加它:
xmlns:tools="http://schemas.android.com/tools"
在您的根布局中。 tools:text 之类的内容将显示在预览中,但当应用程序为 运行 时则不会。所以如下观点:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
tools:text="Preview Text" />
</RelativeLayout>
将在预览中显示 "Preview Text" 的 TextView,但它实际上是 View.GONE,并且在 运行 时没有文本。