2017-09-08 4 views
-1

私はカスタムイメージビューを使用しようとしていますが、それはうまく動作していないと思います。画像が表示されません。私は答えのネットをサーフしたが、答えはすべて混乱している。 :(ここカスタムイメージビューを使用する

は私のXMLです:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="activities.JacintoGate"> 

<activities.ZoomImageView 
    android:name="activities.ZoomImageView" 
    android:id="@+id/jgate_view" 
    android:layout_width="384dp" 
    android:layout_height="566dp" 
    android:scaleType="fitXY" 
    tools:layout_editor_absoluteX="0dp" 
    tools:layout_editor_absoluteY="0dp" /> 

<ImageButton 
    android:id="@+id/imageButton2" 
    style="@android:style/Widget.Holo.Light.ImageButton" 
    android:layout_width="81dp" 
    android:layout_height="59dp" 
    android:layout_marginBottom="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginTop="8dp" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintHorizontal_bias="0.707" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintVertical_bias="0.542" 
    app:srcCompat="@drawable/arrow_up" 
    tools:layout_editor_absoluteY="274dp" 
    tools:layout_editor_absoluteX="209dp" /> 

</android.support.constraint.ConstraintLayout> 

アクティビティ:

public class JacintoGate extends Activity { 

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

private void display() { 

    ZoomImageView imageView = new ZoomImageView(this, getWindow() 
      .getWindowManager().getDefaultDisplay().getOrientation()); 

    imageView.setImage(this.getResources().getDrawable(R.drawable.j_gate), 
      this); 
} 

それは間違っている理由は、私は得ることはありません、私は答えのためにネットサーフィンが、それはすべてのC =そうを見つけます。 :)

+1

どこで 'display'メソッドを呼び出していますか? –

+0

これはonCreateメソッド内にある必要があります。私はそれを簡単な使い方のための関数の中に入れました。私はこのリンクを私のガイドとして使いましたhttp://androidprogrammingmadeeasy.blogspot.com/2011/08/zoom-image-on-double-tap-in-android.html –

+0

しかし、あなたは 'display'を呼んでいるのですか?あなたはコードに何も表示していません –

答えて

0

メソッドdisplayZoomImageViewの新しいインスタンスが作成されますが、xmlに新しいインスタンスが作成されることはありません。あなたの返信から私のコメントに画像を設定する必要があります。onCreate

ZoomImageView imageView = (ZoomImageView) = findViewById(R.Id.jgate_view); 
imageView.setImage(this.getResources().getDrawable(R.drawable.j_gate), this); 
+0

私は試してみましたが、このエラーが出ました 原因:java.lang.NullPointerException:仮想メソッド 'void activities.ZoomImageView.setImage(android.graphics.drawable.Drawable、a​​ndroid.app.Activity ) 'nullのオブジェクト参照で activities.JacintoGate.onCreate(JacintoGate.java:20) –

+0

あなたは 'setContentView'の後にやっていますか? –

+0

まあ、私は気が狂っています。私の質問に答えてくださったことを大変ありがとうございます:) –

関連する問題