缩放根视图后,子视图不可单击
我正在缩放rootView
,它是rootView
fragment
的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页中的视图不可单击。 我该如何解决这个问题?
您应该在xml中将特定的Linear Layout
设置为clickable
,如下所示:
android:clickable="true"
例:
如果您有一个包含三个页面的ViewPager
,并且中心一个应该缩放,那么请使用ViewPager.PageTransformer
进行此操作。
检查这个问题: ViewPager有多个可见的孩子,并选择更大。
基本上,您覆盖transformPage(View view, float position)
并对中心页面进行转换。
对于正常缩放,总是在setScaleBoth()
调用setScaleX()
和setScaleY()
,而不是在onDraw()
调用canvas。