嵌套的 TextView(ConstraintLayout --> LinearLayout)仅在编辑器中可见
TextView in nested (ConstraintLayout --> LinearLayout) visible only in editor
包含在 LinearLayout 中的 ConstraintLayout 中的 TextView 仅在 Android Studio 的预览中可见 window。
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!" 位于屏幕的左上角,如 Preview window here, but instead I see a blank View, as shown in this screenshot 所示,取自使用 "Empty Activity" 项目模板的最小示例,并且如上所示的布局。
尝试使用
android:text="Hello World!"
而不是
tools:text="Hello World!"
我想 Android Studio 已停止发出此类警告。
注意: tools:text
仅用于布局编辑器中标记事物
另一个注意事项:您可以在 activity 中使用 TextView.setText()
作为替代。
包含在 LinearLayout 中的 ConstraintLayout 中的 TextView 仅在 Android Studio 的预览中可见 window。
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!" 位于屏幕的左上角,如 Preview window here, but instead I see a blank View, as shown in this screenshot 所示,取自使用 "Empty Activity" 项目模板的最小示例,并且如上所示的布局。
尝试使用
android:text="Hello World!"
而不是
tools:text="Hello World!"
我想 Android Studio 已停止发出此类警告。
注意: tools:text
仅用于布局编辑器中标记事物
另一个注意事项:您可以在 activity 中使用 TextView.setText()
作为替代。