2016-05-11 70 views
0

在我的android應用程序中,我需要創建活動在我的應用程序中縮放able.nut幾個活動以scrollview開頭,並且此代碼無法識別滾動視圖。我怎樣才能使可縮放活動縮放?這是我的佈局之一。如何在android中放大/縮小滾動視圖?

也還試圖ScaleGestureDetector和 How to make zoomable scrollview?

想要做的放大/縮小滾動視圖。感謝名單您的幫助將appriciated提前

謝謝,這是我的佈局

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/horizontalScrollView" 
android:layout_gravity="center" 
     android:fillViewport="false"> 



    <LinearLayout 
     android:id="@+id/wd_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 

     android:layout_gravity="center" 
     android:gravity="center" 
     android:orientation="vertical" > 

     <!-- Start Circle --> 

     <TableRow 
      android:id="@+id/row_circl1" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_marginTop="30dp" 
      android:background="@mipmap/ic_launcher" > 

      <RelativeLayout 
       android:id="@+id/circle_layout2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/ic_launcher" > 

      </RelativeLayout> 
     </TableRow> 

     <ImageView 
      android:id="@+id/img_engin_circle1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:background="@mipmap/ic_launcher" 
      android:contentDescription="TODO" 
      android:layout_gravity="center_horizontal" /> 

     <TableRow 
      android:id="@+id/row_name_circle" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_marginTop="30dp" > 

      <RelativeLayout 
       android:id="@+id/circle_name_layout1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="-15dp" 
       android:background="@mipmap/ic_launcher" > 

       <ImageView 
        android:id="@+id/img_name_circle1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:background="@mipmap/ic_launcher" 
        android:contentDescription="TODO" /> 

       <ImageView 
        android:id="@+id/img_engin_circle2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@mipmap/ic_launcher" 
        android:contentDescription="TODO" 
        android:layout_alignParentTop="true" 
        android:layout_alignParentStart="true" /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/circle_name_layout2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="-15dp" 
       android:background="@mipmap/ic_launcher" > 

       <ImageView 
        android:id="@+id/img_name_circle2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:background="@mipmap/ic_launcher" 
        android:contentDescription="TODO" /> 


      </RelativeLayout> 
     </TableRow> 

     <RelativeLayout 
      android:id="@+id/circle_layout1" 
      android:layout_width="match_parent" 
      android:layout_height="172dp" 
      android:background="@mipmap/ic_launcher" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentStart="true" 
      android:layout_gravity="right"> 

      <RelativeLayout 
       android:id="@+id/relativeLayout" 
       android:layout_width="match_parent" 
       android:layout_height="172dp" 
       android:background="@mipmap/ic_launcher" 
       android:layout_gravity="right" 
       android:layout_centerVertical="true" 
       android:layout_centerHorizontal="true" /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/circle_layout1" 
      android:layout_width="match_parent" 
      android:layout_height="172dp" 
      android:background="@mipmap/ic_launcher" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentStart="true" 
      android:layout_gravity="right"> 

      <RelativeLayout 
       android:id="@+id/relativeLaysdfout" 
       android:layout_width="match_parent" 
       android:layout_height="172dp" 
       android:background="@mipmap/ic_launcher" 
       android:layout_gravity="right" 
       android:layout_centerVertical="true" 
       android:layout_centerHorizontal="true" /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/circle_laysdfout1" 
      android:layout_width="match_parent" 
      android:layout_height="172dp" 
      android:background="@mipmap/ic_launcher" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentStart="true" 
      android:layout_gravity="right"> 

      <RelativeLayout 
       android:id="@+id/dsf" 
       android:layout_width="match_parent" 
       android:layout_height="172dp" 
       android:background="@mipmap/ic_launcher" 
       android:layout_gravity="right" 
       android:layout_centerVertical="true" 
       android:layout_centerHorizontal="true" /> 
     </RelativeLayout> 

     <!-- End Circle --> 

    </LinearLayout> 



</ScrollView> 

這是我的活動

放大了工作完美,但我不能從左到右或反之亦然,就像在我們的照片花式圖片視圖

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     scrollView = (ScrollView) findViewById(R.id.horizontalScrollView); 
     horizontalScrollView = (HorizontalScrollView) findViewById(R.id.vertical); 

     gestureDetector = new GestureDetector(this, new GestureListener());  

     scaleGestureDetector = new ScaleGestureDetector(this, new ScaleGestureDetector.SimpleOnScaleGestureListener() { 
      @Override 
      public boolean onScale(ScaleGestureDetector detector) { 
       float scale = 1 - detector.getScaleFactor(); 

       float prevScale = mScale; 
       mScale += scale; 

       if (mScale < 0.1f) // Minimum scale condition: 
        mScale = 0.1f; 

       if (mScale > 10f) // Maximum scale condition: 
        mScale = 10f; 
       ScaleAnimation scaleAnimation = new ScaleAnimation(1f/prevScale, 1f/mScale, 1f/prevScale, 1f/mScale, detector.getFocusX(), detector.getFocusY()); 
       scaleAnimation.setDuration(0); 
       scaleAnimation.setFillAfter(true); 

       scrollView.startAnimation(scaleAnimation); 
       horizontalScrollView.startAnimation(scaleAnimation); 
       return true; 
      } 
     }); 
    } 

override dispatchTouchEvent() 
     @Override 
     public boolean dispatchTouchEvent(MotionEvent event) { 
      super.dispatchTouchEvent(event); 
      scaleGestureDetector.onTouchEvent(event); 
      gestureDetector.onTouchEvent(event); 
      return gestureDetector.onTouchEvent(event); 
     } 


     private class GestureListener extends GestureDetector.SimpleOnGestureListener { 
      @Override 
      public boolean onDown(MotionEvent e) { 
       return true; 
      } 
      // event when double tap occurs 
      @Override 
      public boolean onDoubleTap(MotionEvent e) { 
       // double tap fired. 
       return true; 
      } 
     } 
} 
+0

你好,你找到解決方案嗎? – isha

+0

沒有找到合適的解決方案,如果我會,我會分享@isha –

+0

謝謝@mehul的回覆..我需要相同的解決方案 – isha

回答

相關問題