仅在Android Studio的预览窗口中可见。
TextView被限制在父级的开始和顶部,因此应将其放置在视图的左上角。所有三个视图都设置为填充父母的大小。
<?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()
作为替代方案。