缩放rootview后,子视图不可点击 [英] Child views aren't clickable after scaling the rootview

查看:49
本文介绍了缩放rootview后,子视图不可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在缩放ViewPagerfragment中的LinearLayoutrootView,但是子视图不是clickable.

I am scaling rootView which is LinearLayout in fragment of ViewPager but child views aren't 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的相关代码.

Here is relevant code where i am scaling the 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

Each circle is the page of PagerView. 1 - 2 - 3

第2页中的视图是可单击的,但第1页和第3页中的视图则不可单击.我该如何解决这个问题?

Views in page 2 are clickable but views in page 1 and 3 aren't clickable. How can i fix this issue?

推荐答案

如果您有一个包含三个页面的ViewPager,并且应该居中缩放一个页面,则可以使用ViewPager.PageTransformer来实现此目的.

If you have a ViewPager with three pages and centre one should be scaled then use ViewPager.PageTransformer for this purpose.

检查此问题: ViewPager有多个可见的孩子,并选择了更大的孩子.

基本上,您将覆盖transformPage(View view, float position)并进行中心页转换.

Basically you override transformPage(View view, float position) and do your transformation for centre page.

对于常规缩放,请始终在setScaleBoth()中调用setScaleX()setScaleY()而不是在onDraw()中缩放画布.

For normal scaling always call setScaleX() and setScaleY() in setScaleBoth() instead of scaling canvas in onDraw().

这篇关于缩放rootview后,子视图不可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆