如何使 photoview 库与 viewpager 一起工作
how to make photoview library work with viewpager
我是 android 开发新手。我正在使用 photoview 库在我的 imageviewer 应用程序中启用图像缩放。但是 viewpager 和缩放功能不能同时工作 time.When 我在 FullImageActivity.java 中包含 photoView.setVisibility(View.GONE);
,viewpager 开始工作,当我删除它时,缩放能力开始发挥作用。但是 zooming 和 viewpager 不能同时工作。我该如何解决 ?谢谢
完整代码可在 https://github.com/redviper00/game
获得
FullImageActivity.java:
public class FullImageActivity extends AppCompatActivity {
int position;
int folderPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_image);
Intent i = getIntent();
PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
photoView.setVisibility(View.GONE);
// Selected image id
position = i.getExtras().getInt("id");
folderPosition = i.getExtras().getInt("folderPosition");
Bundle extras = getIntent().getExtras();
String value = extras.getString("abc");
Glide.with(FullImageActivity.this)
.load(value)
.skipMemoryCache(false)
.into(photoView);
ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager);
mViewPager.setAdapter(new TouchImageAdapter(this,al_images, folderPosition));
mViewPager.setCurrentItem(position);
}
}
activity_full_image.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/jazzy_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:scaleType="centerCrop"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
自定义 "android:layout_height" 以查看寻呼机和 PhotoView,以便它适用于您......
你已经给了两个匹配父项,所以它不起作用......
您没有在适配器内部使用 Imageview,例如:TouchImageAdapter。
您应该使用 PhotoView 对象,您的问题将得到解决。
PhotoView img = new PhotoView(container.getContext());
请查看我推送到您的存储库的代码更改。
我是 android 开发新手。我正在使用 photoview 库在我的 imageviewer 应用程序中启用图像缩放。但是 viewpager 和缩放功能不能同时工作 time.When 我在 FullImageActivity.java 中包含 photoView.setVisibility(View.GONE);
,viewpager 开始工作,当我删除它时,缩放能力开始发挥作用。但是 zooming 和 viewpager 不能同时工作。我该如何解决 ?谢谢
完整代码可在 https://github.com/redviper00/game
获得FullImageActivity.java:
public class FullImageActivity extends AppCompatActivity {
int position;
int folderPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_image);
Intent i = getIntent();
PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
photoView.setVisibility(View.GONE);
// Selected image id
position = i.getExtras().getInt("id");
folderPosition = i.getExtras().getInt("folderPosition");
Bundle extras = getIntent().getExtras();
String value = extras.getString("abc");
Glide.with(FullImageActivity.this)
.load(value)
.skipMemoryCache(false)
.into(photoView);
ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager);
mViewPager.setAdapter(new TouchImageAdapter(this,al_images, folderPosition));
mViewPager.setCurrentItem(position);
}
}
activity_full_image.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/jazzy_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:scaleType="centerCrop"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
自定义 "android:layout_height" 以查看寻呼机和 PhotoView,以便它适用于您......
你已经给了两个匹配父项,所以它不起作用......
您没有在适配器内部使用 Imageview,例如:TouchImageAdapter。 您应该使用 PhotoView 对象,您的问题将得到解决。
PhotoView img = new PhotoView(container.getContext());
请查看我推送到您的存储库的代码更改。