2016-04-03 10 views
0

の子供のためのsetOnClickListener私はRelativeLayoutアンドロイド:RelativeLayout

を使用しかし、このレイアウトの子供たちはそれを固定する方法

を、のsetTextために働くクリックして...ありませんか?

コード:

ImageView ImageView01 = (ImageView) findViewById(R.id.ImageView01); 
if (ImageView01 != null) { 
    ImageView01.setOnClickListener(new OnClickListener() { 
     public void onClick(View arg0) { 
      Log.i("error", "q" + 108); 
     } 
    }); 
} 

RelativeLayout

XMLののLinearLayout子のためにこのコード:

<LinearLayout 
android:id="@+id/lnrVideoControl" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/imgPlayVideo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.5" 
    android:focusable="false" 
    android:src="@drawable/play" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="15dp" 
    android:layout_marginRight="15dp" 
    android:layout_marginTop="5dp" 
    android:layout_weight="0.5" 
    android:gravity="center" > 

    <SeekBar 
     android:id="@+id/seekBarVideo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="7dp" 
     android:layout_marginTop="2dp" 
     android:layout_weight="0.5" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" 
     android:progressDrawable="@drawable/red_scrubber_progress" 
     android:thumb="@drawable/red_scrubber_control_thin" 
     android:thumbOffset="8dp" /> 
</LinearLayout> 

RelativeLayoutからこのコードを使用すると、完全に機能します。

どのようにこの問題を解決しますか?

+0

RelativeLayoutの子に対してlayout_weightをどのように設定していますか? ImageViewからクリック可能な属性を削除します。 – droidev

+0

私は質問 –

+0

を更新する答えを確認し、それが動作していない場合はお知らせください – droidev

答えて

0

IDがimgPlayVideoのImageViewがあります。しかし、他のImageViewへの参照を作成しています。

ImageView ImageView01 = findViewById(R.id.ImageView01) 

これは間違った参照です。したがって、コードを修正して正確なImageViewを参照してください。

ImageView imageView = findViewById(R.id.imgPlayVideo) 

これで問題が解決する可能性があります。

+0

申し訳ありませんが、私は画像ビューの名前を変更します。このコードはうまくいきません:( –

+0

あなたのイメージ内にログを入れてくださいnullチェックとそれが来ているかどうかを確認してくださいlayout_widthを0dpに変更してください。垂直方向のLinearLayoutにウェイトを使用しています – droidev

+0

このコードも機能しません:TextView txtVideoEnd = )G.currentActivity.findViewById(R.id.txtVideoEnd); txtVideoEnd.setText( "123"); –

関連する問題