Viewpager中的Android缩放缩放布局,左侧和右侧填充
我有一个带左右边距的viewpager,用于显示viewpager左右页面的预览.
I have a viewpager with left and right padding for showing the previews of left and right pages of viewpager.
viewPager.setPadding(30,0,30,0);
viewpager的内容是从此处借用的缩放布局. 因此,问题是,每当我从viewpager缩放布局时,唯一可见的缩放位于顶部和底部.由于填充,左右无法看到缩放.
The content of the viewpager is a zoomlayout borrowed from here. So the issue is, whenever I zoom the layout from the viewpager, the only visible zoom is at top and bottom. Zooming is not visible to the left and right due to padding.
缩放前的屏幕截图
缩放后的屏幕截图
Screenshot after zooming
缩放视图仅限于viewpager填充内.我需要视图全屏缩放,没有任何填充或边界.
The zoomed view is limited inside the viewpager padding. I need the view to zoom fullscreen without any padding or boundaries.
这些是我正在尝试的代码段
These are the code snippets I was trying
activity_reader.xml
activity_reader.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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:layout_width="match_parent"
android:layout_height="match_parent">
<ViewPager
android:id="@+id/reader_pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000"/>
</FrameLayout>
each_page.xml
each_page.xml
<?xml version="1.0" encoding="utf-8"?>
<com.test.poc.widgets.ZoomLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/zoom_layout">
<RelativeLayout
android:id="@+id/img_holder"
android:transitionName="pager"
android:background="#FFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/page_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/a_four"
android:layout_weight="1"
android:scaleType="fitXY"
/>
</RelativeLayout>
</com.test.poc.widgets.ZoomLayout>
缩放视图后,松开手指时,视图应平滑移动到全屏viewpager.
After zooming the view, when I release the finger, the view should move smoothly to a fullscreen viewpager.
尝试将clipToPadding设置为false,但是在缩放时填充的一侧仍然存在
Tried setting clipToPadding as false, but still one side of padding still exist while zooming
Try this, it's worked for me using this :https://gist.github.com/atermenji/3781644
public class ImageZoomViewPager extends ViewPager {
public ImageZoomViewPager(Context context) {
super(context);
}
public ImageZoomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (v instanceof ImageViewTouch) {
return ((ImageViewTouch) v).canScroll(dx);
} else {
return super.canScroll(v, checkV, dx, x, y);
}
}}