2012-09-03 54 views
2

我是新來的android,我必須對現有的應用程序進行改進。在這個應用程序的內部,我們有一個相對的佈局,一組15個圖像視圖,一個動態圖像視圖和兩個文本視圖,我必須編程縮放控件以放大和縮小。最近幾天,我一直在不斷閱讀本網站,試圖在現有問題中找到答案而沒有任何結果,因爲很多問題都沒有答案。以相對佈局縮放多個圖像的控件

我最大的問題是我不知道要使用哪個框架或佈局。所有圖像都放置在相對佈局中,並且運行良好,但我似乎沒有得到使用內容的縮放控件,並且我已經閱讀了不同的線程和問題,以致RelativeLayout無法使用縮放。我想也許使用FrameLayout,但我認爲它有同樣的問題。

這是從佈局的XML代碼:

<RelativeLayout 
     android:id="@+id/relativeLayoutMachine" 
     android:layout_width="1000dp" 
     android:layout_height="550dp" 
     android:layout_above="@+id/relativeLayout1" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:background="@color/brm_back_1" > 

     <ImageView 
      android:id="@+id/imageView01" 
      android:layout_width="82dp" 
      android:layout_height="67dp" 
      android:layout_marginLeft="409dp" 
      android:layout_marginTop="83dp" 
      android:contentDescription="@id/imageVeuwBandInloopKoker" 
      android:src="@drawable/lva_bandinloopkoker" /> 

     <ImageView 
      android:id="@+id/imageView02" 
      android:layout_width="82dp" 
      android:layout_height="67dp" 
      android:layout_marginLeft="409dp" 
      android:layout_marginTop="149dp" 
      android:contentDescription="@id/imageViewTussenKoker" 
      android:src="@drawable/lva_tussenkoker" /> 

     <ImageView 
      android:id="@+id/imageView03" 
      android:layout_width="172dp" 
      android:layout_height="88dp" 
      android:layout_marginLeft="401dp" 
      android:layout_marginTop="216dp" 
      android:contentDescription="@id/imageViewHMI_Graph_04_Flap" 
      android:src="@drawable/lva_flap_open" /> 

     <ImageView 
      android:id="@+id/imageView04" 
      android:layout_width="281dp" 
      android:layout_height="61dp" 
      android:layout_marginLeft="401dp" 
      android:layout_marginTop="303dp" 
      android:contentDescription="@id/imageViewHMI_Graph_03_Ram" 
      android:src="@drawable/lva_ram_retour" /> 

     <ImageView 
      android:id="@+id/imageView05" 
      android:layout_width="110dp" 
      android:layout_height="47dp" 
      android:layout_marginLeft="571dp" 
      android:layout_marginTop="257dp" 
      android:contentDescription="@id/imageViewHMI_Graph_01_Unit" 
      android:src="@drawable/lva_unit" /> 

     <ImageView 
      android:id="@+id/imageView06" 
      android:layout_width="51dp" 
      android:layout_height="54dp" 
      android:layout_marginLeft="431dp" 
      android:layout_marginTop="28dp" 
      android:contentDescription="@id/imageViewHMI_Graph_15_Feeder" 
      android:src="@drawable/lva_feeder_off" /> 

     <ImageView 
      android:id="@+id/imageView07" 
      android:layout_width="90dp" 
      android:layout_height="40dp" 
      android:layout_marginLeft="585dp" 
      android:layout_marginTop="218dp" 
      android:contentDescription="@id/imageViewHMI_Graph_02_Pump" 
      android:src="@drawable/lva_main_motor_off" /> 

     <ImageView 
      android:id="@+id/imageView08" 
      android:layout_width="199dp" 
      android:layout_height="124dp" 
      android:layout_marginLeft="157dp" 
      android:layout_marginTop="240dp" 
      android:contentDescription="@id/imageViewChannel" 
      android:src="@drawable/lva_channel" /> 

     <ImageView 
      android:id="@+id/imageView09" 
      android:layout_width="82dp" 
      android:layout_height="166dp" 
      android:layout_marginLeft="410dp" 
      android:layout_marginTop="50dp" 
      android:contentDescription="@id/imageViewHMI_Graph_013_Turbo" 
      android:src="@drawable/lva_turbo_off" 
      android:visibility="invisible" /> 

     <ImageView 
      android:id="@+id/imageView10" 
      android:layout_width="88dp" 
      android:layout_height="67dp" 
      android:layout_marginLeft="402dp" 
      android:layout_marginTop="149dp" 
      android:contentDescription="@id/imageViewHMI_Graph_012_Perforator" 
      android:src="@drawable/lva_perforator_off" 
      android:visibility="invisible" /> 

     <ImageView 
      android:id="@+id/ImageView11" 
      android:layout_width="88dp" 
      android:layout_height="67dp" 
      android:layout_marginLeft="408dp" 
      android:layout_marginTop="149dp" 
      android:contentDescription="@id/ImageViewHMI_Graph_10_Ruffler" 
      android:src="@drawable/lva_ruffler_off" 
      android:visibility="invisible" /> 

     <ImageView 
      android:id="@+id/ImageView12" 
      android:layout_width="174dp" 
      android:layout_height="72dp" 
      android:layout_marginLeft="362dp" 
      android:layout_marginTop="146dp" 
      android:contentDescription="@id/ImageViewHMI_Graph_11_Prepress" 
      android:src="@drawable/lva_prepress_open" 
      android:visibility="invisible" /> 

     <ImageView 
      android:id="@+id/imageView13" 
      android:layout_width="46dp" 
      android:layout_height="68dp" 
      android:layout_marginLeft="356dp" 
      android:layout_marginTop="297dp" 
      android:contentDescription="@id/imageViewHMI_Graph_07_Needles_Hor" 
      android:src="@drawable/lva_needles_hor_none" /> 

     <ImageView 
      android:id="@+id/imageView14" 
      android:layout_width="44dp" 
      android:layout_height="111dp" 
      android:layout_marginLeft="356dp" 
      android:layout_marginTop="187dp" 
      android:contentDescription="@id/imageViewHMI_Graph_05_Needles_Vert" 
      android:src="@drawable/lva_needles_vert_high" /> 

     <ImageView 
      android:id="@+id/imageView15" 
      android:layout_width="10dp" 
      android:layout_height="24dp" 
      android:layout_marginLeft="371dp" 
      android:layout_marginTop="272dp" 
      android:contentDescription="@id/imageViewHMI_Graph_06_Knotter_Vert" 
      android:src="@drawable/lva_motor_off" /> 

     <FrameLayout 
      android:id="@+id/frameLayoutBale" 
      android:layout_width="140dp" 
      android:layout_height="51dp" 
      android:layout_marginLeft="19dp" 
      android:layout_marginTop="307dp" > 

      <ImageView 
       android:id="@+id/imageViewAnimation" 
       android:layout_width="140dp" 
       android:layout_height="51dp" 
       android:layout_gravity="right" 
       android:contentDescription="@id/imageViewHMI_Graph_Bale" 
       android:scaleType="fitXY" 
       android:src="@drawable/baal" /> 

     </FrameLayout> 

     <TextView 
      android:id="@+id/textView01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="110dp" 
      android:layout_marginTop="316dp" 
      android:gravity="right" 
      android:text="@string/percentage" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@color/brm_back_2" /> 

     <TextView 
      android:id="@+id/textView02" 
      android:layout_width="142dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="22dp" 
      android:layout_marginTop="271dp" 
      android:gravity="center" 
      android:text="@string/puntjes" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@color/brm_back_2" /> 

     <ZoomControls 
      android:id="@+id/zoomControls" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_alignRight="@+id/textCurrMaterial" /> 

    </RelativeLayout> 

這是我在我的主要用於聲明縮放控件的代碼:

btnZoomControls = (ZoomControls) findViewById(R.id.zoomControls); 
btnZoomControls.setOnZoomInClickListener(new View.OnClickListener() {public void onClick(View v) {setZoomIn(); }}); 
btnZoomControls.setOnZoomOutClickListener(new View.OnClickListener() {public void onClick(View v) {setZoomOut(); }}); 

這是函數進行放大並出

private void setZoomIn() 
{ 
    m_ZoomController.getContainer(); 
    m_ZoomController.getZoomControls(); 
    m_ZoomController.setZoomInEnabled(true); 
} 

private void setZoomOut() 
{ 
    m_ZoomController.getContainer(); 
    m_ZoomController.getZoomControls(); 
    m_ZoomController.setZoomOutEnabled(true); 
} 

有沒有像我的類似問題,以及你如何找到解決方案來解決它?

+0

'ZoomControls'只是2個按鈕,沒有更多的功能,而不是尋找你想要的方式。他們自己不做任何事情,特別是不放大任何內容。 – zapl

+0

我的問題是,這種或那種方式,我必須放大我在那裏的內容,使用我發現與否的工具。如果我無法使用縮放控件做什麼,那麼我必須通過其他方式來放大我在相對佈局中的圖像。 –

+0

縮放圖像不是android的標準功能,你需要做一些像http://stackoverflow.com/questions/2537238/how-can-i-get-zoom-functionality-for-images(自定義實現例如'ImageView '或者嘗試'WebView')來獲得這個功能。 – zapl

回答

3

其實,你有變焦兩種主要方式:

1)呼叫setScaleX() and setScaleY()(因爲在整個佈局上或特定視圖API 11)。根據我的經驗,圖像縮放工作正常,但某些版本的文本會產生奇怪的行爲(此縮放在繪製過程中由視圖組應用,因此速度非常快)。這種方式對於不太大的佈局非常平滑和快速;

2)更改每個視圖的佈局參數(您可能需要,可能需要在縮放過程中爲圖像視圖提供新圖片)。這種方式不是那麼快,但應該在幾乎所有的android修訂版上工作。

+0

我用你告訴我的按鈕,它工作正常!現在我必須執行拖放操作,但爲此我找到了幾個問題和答案來幫助我。非常感謝!!! –