在 Eclipse 中包含 Android-DirectionalViewPager .jar 时出错

2022-01-19 00:00:00 android android-viewpager eclipse

我正在尝试在我的应用中实现垂直滑动.(就像使用 ViewPager 滑动一样,但垂直滑动).

I am trying to implement vertical swiping in my app. (Its just like the swiping with ViewPager, but vertically).

我找到了 Jake Whartons 库 Android-DirectionalViewPager.它是一个独立的 .jar 文件,除了兼容性库之外,还应包括在内.我将文件包含在我的项目中.它现在位于引用库"下,就像兼容性库一样.
但问题是,我什至无法让图书馆提供的示例正常工作.调试器停在行

I found Jake Whartons library Android-DirectionalViewPager. It is a standalone .jar file which should be included in addition to the compatibility library. I included the file in my project. It is now under 'Referenced Libraries', just like the compatibility library.
But the problem is, I cant even get the example, which is given with the library, to work. The debugger stops at line

setContentView(R.layout.main);

带有未找到来源"

LogCat 抛出此错误:05-23 14:43:13.583: E/dalvikvm(329): 找不到类 'com.directionalviewpager.DirectionalViewPager',引用自方法 own.vvp.MainActivity.onCreate"

LogCat throws this error: "05-23 14:43:13.583: E/dalvikvm(329): Could not find class 'com.directionalviewpager.DirectionalViewPager', referenced from method own.vvp.MainActivity.onCreate "

有人已经使用过这个库吗?我需要一些帮助:)

Has somebody already used this library? I need some help :)

这是我的代码:

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="own.vvp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

布局:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<com.directionalviewpager.DirectionalViewPager
    android:id="@+id/pager"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="2dp"
    android:orientation="horizontal">

    <Button
        android:id="@+id/horizontal"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginRight="1dp"
        android:text="Horizontal" />
    <Button
        android:id="@+id/vertical"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginLeft="1dp"
        android:text="Vertical" />

</LinearLayout>

</LinearLayout>

和主要活动:

package own.vvp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import com.directionalviewpager.DirectionalViewPager;


public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //Set up the pager
    final DirectionalViewPager pager = (DirectionalViewPager)findViewById(R.id.pager);
    pager.setAdapter(new TestFragmentAdapter(getSupportFragmentManager()));

    //Bind to control buttons
    ((Button)findViewById(R.id.horizontal)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setOrientation(DirectionalViewPager.HORIZONTAL);
        }
    });
    ((Button)findViewById(R.id.vertical)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setOrientation(DirectionalViewPager.VERTICAL);
        }
    });
}
}

和例子中的代码一样,除了包名和主activity的名字,所以我猜,我包含库的方式一定是错误的.

it is the same code as in the example, except for the package name and the name of the main activity, so I guess, the way I included the library must be wrong.

谢谢!

推荐答案

更新(2 月 1 日 14 日): 这个库是一个非常好的选择.我目前在我的项目中使用它,它工作得很好.它仍在维护中,它是对来自支持库 r19 的标准 ViewPager 的非常接近的修改.另一个优点是,如果您使用 gradle,您可以通过 maven Central 轻松集成和解决它.

Update (Feb 1st 14): This library is a really good alternative. I'm currently using it in my project and it's working flawlessly. It's still being maintained and it's a very close modification of the standard ViewPager from support lib r19. Another advantage is, that you can easily integrate and resolve it via maven central, if you're using gradle.

https://github.com/castorflex/VerticalViewPager

感谢 Oleg Vaskevich,我能够从当前的 git 文件和 oleg 的添加/修复中编译出一个新的和工作的 directionalViewpager jar 文件.我可以确认它适用于当前的 support-lib v4 r11.

Thanks to Oleg Vaskevich, I was able to compile a new and working directionalViewpager jar-file from the current git files and oleg's additions/fixes. I can confirm that it's working with the current support-lib v4 r11.

https://dl.dropbox.com/u/24363935/android-directionalviewpager-1.2.1fixed.jar

希望这对某人有用:)

补充:我在 DirectionalViewPager.setAdapter(PagerAdapter adapter){...}; 中有一个 IllegalArgumentException.所以我已经修改并修复,重新编译并上传了新的jar.

to add: I had an IllegalArgumentException in DirectionalViewPager.setAdapter(PagerAdapter adapter){...};. So I've modified and fixed, recompiled and uploaded the new jar.

相关文章