Views for children cannot be changed after scaling the root view

I scale the rootView , which LinearLayout to fragment from ViewPager , but the child views are not clickable .

This is 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 } } 

Here is the relevant code where I scale 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); 

What does it look like.

enter image description here

Each circle is a PagerView page. 1 - 2 - 3

The views on page 2 are viewable, but the views on pages 1 and 3 are not viewable. How can I fix this problem?

0
java android android-viewpager android-view android-animation
Jul 13 '17 at 6:29
source share
2 answers

You should set this Linear Layout as clickable in your xml, as shown below:

 android:clickable="true" 

Example:

  <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> 
0
Jul 13 '17 at 6:37
source share
— -

If you have a ViewPager with three pages and a center, you need to scale, then use ViewPager.PageTransformer for this purpose.

Check this question: ViewPager with several visible children and more selected.

Basically you override transformPage(View view, float position) and do the conversion for the center page.

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

0
Jul 13 '17 at 8:53 on
source share



All Articles