android - 嵌套中的 TextView (ConstraintLayout --> LinearLayout) 仅在编辑器中可见
问题描述
包含在 LinearLayout 中的 ConstraintLayout 中的 TextView 仅在 Android Studio 的预览窗口中可见。
TextView 被限制在父级的开始和顶部,所以它应该放在 View 的左上角。所有三个视图都设置为填充父级的大小。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" >
<android.support.constraint.ConstraintLayout
android:id="@+id/view_downloads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"> <!-- default -->
<TextView
android:id="@+id/textview_downloads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="@android:style/TextAppearance.Material.Large"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Hello World!" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
我希望看到“Hello World!” 放置在屏幕的左上角,如此处的预览窗口所示,但我看到的是一个空白视图,如此屏幕截图所示,取自使用“空活动”项目模板和所示布局的最小示例多于。
解决方案
尝试使用
android:text="Hello World!"
代替
tools:text="Hello World!"
我猜 Android Studio 已经停止发出这些警告。
注意: tools:text
仅在布局编辑器中用于标记事物
另一个注意事项:您可以TextView.setText()
在您的活动中使用作为替代。
推荐阅读
- java - 在 Eclipse 中,如何运行引用一个类的所有 junit 测试
- python - 不会打印项目列表,只打印列表中的第一项
- oracle - HY010 SSIS 中的 Oracle ODBC 函数序列错误?
- azure - ImagePullBackOff 未经授权:需要身份验证
- javascript - 浏览器需要 HTTP 响应,但服务器不允许多个响应
- parsing - 除了叶子,如何创建相同的树?
- c - 如何在C中实现多关键字搜索?
- git - Git 认为我正在推送到不同的(不存在的)存储库?
- java - 如果我的 JVM 是 1.8,为什么我必须将 targetCompatibility 设置为 JavaVersion.VERSION_1_8
- java - c:if 带有来自模型的变量