2016-04-03 35 views
0

的孩子我用RelativeLayout安卓:setOnClickListener为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的

的LinearLayout中的孩子

XML:

<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

您有一个ImageView,ID为imgPlayVideo。但是您正在创建对其他一些ImageView的引用。

ImageView ImageView01 = findViewById(R.id.ImageView01) 

这可能是一个错误的参考。因此请更正您的代码并参考确切的ImageView

ImageView imageView = findViewById(R.id.imgPlayVideo) 

这可能会解决您的问题。

+0

对不起,我更改imageview的名称。此代码不起作用:( –

+0

在你的imageView空检查中放入一个日志,看看它是否会到来,并且将layout_width更改为0dp,因为你正在使用垂直定向LinearLayout的权重 – droidev

+0

此代码也不起作用:TextView txtVideoEnd =(TextView )G.currentActivity.findViewById(R.id.txtVideoEnd); txtVideoEnd.setText(“123”); –

相关问题