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

import "android.support.v4.view.ViewPager" in activity_main.xml file

我想从教程中学习滑动技术来更改我的页面。在那个教程中,他在 xml 主文件中使用了 "android.support.v4.view.ViewPager"。但我不知道我必须在 android studio environment.my 的文件中的什么地方附加此代码主要问题是当我在我的 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.0.1\aapt.exe'' finished with non-zero exit value 1

编辑:查看我为您创建的要点 https://gist.github.com/akodiakson/7e77790317d86e7a6bee

问题是 RelativeLayout 没有关闭。您的 ViewPager 需要在 RelativeLayout.

内声明

--

在您的 build.gradle 中,您需要添加 v4 支持库

compile com.android.support:support-v4:23.0.1 //或者你需要或拥有的任何版本

在另一个布局文件中,您需要声明一个 ViewPager 布局。

<android.support.v4.view.ViewPager ... ></android.support.v4.view.ViewPager>

编辑如下你错过了“<”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" />