android - 无法理解此代码功能

标签 android

<LinearLayout 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"
 android:gravity="center"
 android:orientation="vertical"
 tools:context="com.bignerdranch.android.geoquiz.CheatActivity">
 <TextView
  android:id="@+id/answer_text_view"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:padding="24dp"
  tools:text="Answer"/>

我是编程新手。我从 Big Nerd Ranch 编程书开始。我遇到了这段代码。书中是这样写的:

"This namespace allows you to override any attribute on a widget for the purpose of displaying it differently in the Android Studio preview. Since TextView has a text attribute, you can provide a literal dummy value for it to help you know what it will look like at runtime. The value “Answer” will never show up in the real app. Handy!"

这到底是什么意思?我是全新的。我知道这是个愚蠢的问题,请帮助我。

最佳答案

感谢那条线

xmlns:tools="http://schemas.android.com/tools"

你可以在你所有的 XML 中使用类似的东西

tools:text="Answer"

感谢那条线

xmlns:android="http://schemas.android.com/apk/res/android"

例如,您可以在所有 XML 元素中使用 android 属性

android:id="@+id/answer_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"

您正在阅读的这本书是一本好书,请继续阅读,不要放弃!

关于android - 无法理解此代码功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41832760/

相关文章:

android - 更改 map View 中指南针的位置

android - 如果值在OpenAPI生成器的Moshi中不匹配,如何退回枚举

android - 新的分页库也可以与 Firebase 一起使用?

android - 位图到垫子?安卓opencv

android - 确定android中的互联网速度

java - 连接到google fit android API不在 Activity 类中

java - 从错误的文件夹中获取的维度值

android - 如何从图像计算高度而又不与光源距离

android - 以编程方式分配资源 ID

android - 我怎样才能让 recyclerView 在 android 约束布局中占据一半的屏幕(最大)?