0

我縮放rootView即的ViewPager但子視圖不是clickable縮放rootview後,子視圖不可點擊

這是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); 

這就是它的樣子。

enter image description here

每個圓圈是PagerView頁面。 1 - 2 - 3

頁面2中的視圖可點擊,但頁面1和3中的視圖不可點擊。我該如何解決這個問題?

回答

0

應設置特定Linear Layoutclickable在XML象下面這樣:

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> 
+0

這不起任何作用。如果我添加此屬性,那麼它會使頁面不響應點擊事件。 –

0

如果你有一個ViewPager有三頁和中心應該被縮放然後使用ViewPager.PageTransformer爲此目的。

檢查這個問題:ViewPager with mutiple visible children and selected bigger.

基本上你重寫transformPage(View view, float position)做你改造爲中心頁面。

對於正常縮放比例,總是在setScaleBoth()中調用setScaleX()setScaleY(),而不是在onDraw()中縮放畫布。

+0

我試過這樣做,但是這弄亂了用戶界面。我只在屏幕上看到一個圓圈。我想要顯示3個圈子,中間的一個應該比左右和旋轉效果還要大。 –