我正在缩放rootView,它是fragment of ViewPager中的LinearLayout,但是子视图不是clickable。
这是rootView
public class CarouselLinearLayout extends LinearLayout {
private float scale = CarouselPagerAdapter.BIG_SCALE;
public CarouselLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CarouselLinearLayout(Context context) {
super(context);
}
public void setScaleBoth(float scale) {
this.scale = scale;
this.invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// The main mechanism to display scale animation, you can customize it as your needs
int w = this.getWidth();
int h = this.getHeight();
h = h - ((h / 2) / 2) / 2;
canvas.scale(scale, scale, w / 2, h);// / 2
}
}下面是我缩放rootview的相关代码。
LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.pager_fragment_dashboard, container, false);
CarouselLinearLayout root = (CarouselLinearLayout) linearLayout.findViewById(R.id.root_container);
root.setScaleBoth(scale);看起来就是这样。

每个圆圈都是PagerView的页面。1-2-3
页面2中的视图是可点击的,但页面1和3中的视图是不可点击的。如何解决此问题?
发布于 2017-07-13 14:37:20
您应该在xml中将该特定Linear Layout设置为clickable,如下所示:
android:clickable="true"示例:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:clickable="true"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>发布于 2017-07-13 16:53:30
如果你有一个三页的ViewPager,中间的一页应该缩放,那么可以使用ViewPager.PageTransformer来实现这个目的。
检查这个问题:ViewPager with mutiple visible children and selected bigger.
基本上,您可以覆盖transformPage(View view, float position)并对中心页面进行转换。
对于正常缩放,始终在setScaleBoth()中调用setScaleX()和setScaleY(),而不是在onDraw()中缩放画布。
https://stackoverflow.com/questions/45072946
复制相似问题