android - 在 activity_main.xml 文件中导入 "android.support.v4.view.ViewPager"

标签 android android-viewpager

我想从教程中学习滑动技术来更改我的页面。在该教程中,他在主 xml 文件中使用了“android.support.v4.view.ViewPager”。但我不知道我必须在 android studio 环境中的文件中的什么位置附加此代码。我的主要问题是当我在我的 xml 代码的每个地方附加“android.support.v4.view.ViewPager”时,它表示错误并且我不知道哪里是正确的附加位置。这是我的主要 xml 文件:

<RelativeLayout

    android.support.v4.view.ViewPager  // error  is here
    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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

gradle 中的错误是:

Error:(3) Error parsing XML: not well-formed (invalid token)
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\iman\AppData\Local\Android\sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1

最佳答案

如下编辑你错过了“<”android.support.v4.view.ViewPager

<RelativeLayout

<android.support.v4.view.ViewPager  // error  is here
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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

关于android - 在 activity_main.xml 文件中导入 "android.support.v4.view.ViewPager",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32593932/

相关文章:

android - 查看分页器2/回收器 View 崩溃的不一致

android - 数据库未在 OnePlus 2 中正确复制

android - 如何将标题添加到 Android Picasso

android - 在 android 的 nestedscrollview 中使用 3 个 recyclerviews 时滚动不流畅

android - Cover Flow 功能使用 view pager android

android - Viewpager 的静态页眉和页脚

android - ViewPager 和 fragment — 设计嵌套 fragment 或 ..?

android - 使用 BlueStacks 调试 Kivy android 应用程序

android - 如何在 android 中使用 Switch 小部件

Android Google Play 服务为 blogger api 返回无效 token