2013-05-20 33 views
1

我想實現android-zoom-view(https://code.google.com/p/android-zoom-view/)。 我將jar添加到構建路徑。我創建了以下XML:如何實現android zoomview?

<?xml version="1.0" encoding="utf-8"?> 
<pl.polidea.view.ZoomView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

    <ImageView 
     android:id="@+id/webcam1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:layout_marginBottom="20dp" 
     android:scaleType="matrix" /> 

    <ImageView 
     android:id="@+id/webcam2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:scaleType="matrix" /> 
</pl.polidea.view.ZoomView> 

和下面的代碼添加到我的活動:

View v = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)) 
      .inflate(R.layout.zoomable_view, null, false); 
    v.setLayoutParams(new LinearLayout.LayoutParams(
      LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

    zoomView = new ZoomView(this); 
    zoomView.addView(v); 

    LinearLayout main_container = (LinearLayout) findViewById(R.id.LinearLayout1); 
    main_container.addView(zoomView); 

我究竟做錯了什麼? 我得到以下錯誤:

Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class pl.polidea.view.ZoomView 

回答

5

我在ZoomView類中添加了以下構造函數,它現在至少適用於zoomview中的一個imageview。

public ZoomView(final Context context, AttributeSet attr) { 
    super(context, attr);  
} 
+0

是的,那是爲我做的。 –

-1

只需添加JAR文件到構建路徑不起作用。 你必須去「訂購和導出標籤」,並檢查jar文件以包含在classpath中。 (訂單和導出選項卡可在項目的屬性菜單中找到。)

+0

謝謝。我現在在「訂單和導出標籤」中啓用了jar文件。但問題依然存在。 – iischwuerfl

+0

用於zoomview的Xml suppoert還未到來。 請參考:https://code.google.com/p/android-zoom-view/issues/detail?id=2 –