我正在关注下载android studio以及如何设置它的课程,我已经为我的手机下载了正确的驱动程序但是当我尝试运行我的hello world程序时我遇到了问题.
请记住,课程本身建议我更新名为activity_main.xml的文件.这是该文件的先前内容:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.udacity.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintLeft_toLeftOf="@+id/activity_main"
app:layout_constraintTop_toTopOf="@+id/activity_main"
app:layout_constraintRight_toRightOf="@+id/activity_main"
app:layout_constraintBottom_toBottomOf="@+id/activity_main" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
必须更新此代码才能与视频保持一致.新细分:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.udacity.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
当我尝试在手机上运行应用程序时,我得到的是:
Error:(7, 28) No resource found that matches the given name (at ‘paddingBottom’ with value ‘@dimen/activity_vertical_margin’).
Error:(8, 26) No resource found that matches the given name (at ‘paddingLeft’ with value ‘@dimen/activity_horizontal_margin’).
Error:(9, 27) No resource found that matches the given name (at ‘paddingRight’ with value ‘@dimen/activity_horizontal_margin’).
Error:(10, 25) No resource found that matches the given name (at ‘paddingTop’ with value ‘@dimen/activity_vertical_margin’).
Error:Execution failed for task ‘:app:processDebugResources’.
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
从RelativeLayout中删除这些行:
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
Run Code Online (Sandbox Code Playgroud)
或者更改值:
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
Run Code Online (Sandbox Code Playgroud)
@dimen/...是对res/values/dimens.xml文件中的维度值的引用.你可能没有任何值,这就是你得到这个错误的原因.
| 归档时间: |
|
| 查看次数: |
597 次 |
| 最近记录: |