<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/