2013-03-28 80 views
0

我有我的佈局xml文件:Back Image按鈕不可點擊?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/relativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/screen_background">  

    <ImageButton 
android:id="@+id/back_btn" 
android:layout_width="30dp" 
android:layout_height="190dp" 
android:layout_alignParentLeft="true" 
android:layout_centerVertical="true" 
android:layout_marginLeft="-5dp" 
android:background="@drawable/button_movielist_back" 
/> 

<LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" 
       android:layout_alignBottom="@+id/linearLayout01" 
       android:layout_marginBottom="55dp"> 



<ImageView 
        android:id="@+id/imageView1" 
        android:layout_width="fill_parent" 
        android:layout_height="50dp" 
        android:src="@drawable/tone_movies_banner" 
        android:layout_alignParentTop="true" 
        android:scaleType="fitXY"/> 

<HorizontalScrollView 
       android:id="@+id/horizontalScroll" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <LinearLayout 
        android:id="@+id/linearLayout3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">      

        <Button 
           android:id="@+id/actionBtn" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:background="@drawable/button_action_movies"     
           android:onClick="btnClicker"/> 

         <Button 
           android:id="@+id/comedyBtn" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:background="@drawable/button_comedy_movies"    
           android:onClick="btnClicker" /> 

         <Button 
           android:id="@+id/loveBtn" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:background="@drawable/button_love_movies"     
           android:onClick="btnClicker" /> 

      </LinearLayout> 
     </HorizontalScrollView> 

<LinearLayout 
      android:id="@+id/linearLayout01" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp"   
      android:layout_alignParentBottom="true" 
      android:layout_marginBottom="5dp"> 
    </LinearLayout> 

</LinearLayout> 
</RelativeLayout> 

的返回按鈕圖像我試圖從佈局設置爲:

<ImageButton 
android:id="@+id/back_btn" 
android:layout_width="30dp" 
android:layout_height="190dp" 
android:layout_alignParentLeft="true" 
android:layout_centerVertical="true" 
android:layout_marginLeft="-5dp" 
android:background="@drawable/button_movielist_back" 
/> 

代碼:

// Previous Button 
        ImageButton backBtn = (ImageButton) findViewById(R.id.back_btn); 
        backBtn.setOnClickListener(new View.OnClickListener() { 

         public void onClick(View v) { 
          Toast.makeText(v.getContext(), "Hello!! button Clicked", Toast.LENGTH_SHORT).show(); 
          //Intent i = new Intent(getBaseContext(), SpecificationsActivity.class); 
          //i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
          //ShortfilmCategoryviewActivity.this.startActivity(i); 

         } 
        }); 

當我點擊backimagebutton ,它不可點擊

我認爲問題persi st在佈局xml文件中

任何人都可以告訴我從我的佈局文件放置imagebutton是否正確?

回答

3

我認爲你的線性佈局是在imageButton上方,這就是爲什麼你不能訪問ImageButton。

編輯

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/relativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/screen_background">  



<LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" 
       android:layout_alignBottom="@+id/linearLayout01" 
       android:layout_marginBottom="55dp"> 



<ImageView 
        android:id="@+id/imageView1" 
        android:layout_width="fill_parent" 
        android:layout_height="50dp" 
        android:src="@drawable/tone_movies_banner" 
        android:layout_alignParentTop="true" 
        android:scaleType="fitXY"/> 

<HorizontalScrollView 
       android:id="@+id/horizontalScroll" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <LinearLayout 
        android:id="@+id/linearLayout3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">      

        <Button 
           android:id="@+id/actionBtn" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:background="@drawable/button_action_movies"     
           android:onClick="btnClicker"/> 

         <Button 
           android:id="@+id/comedyBtn" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:background="@drawable/button_comedy_movies"    
           android:onClick="btnClicker" /> 

         <Button 
           android:id="@+id/loveBtn" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:background="@drawable/button_love_movies"     
           android:onClick="btnClicker" /> 

      </LinearLayout> 
     </HorizontalScrollView> 

<LinearLayout 
      android:id="@+id/linearLayout01" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp"   
      android:layout_alignParentBottom="true" 
      android:layout_marginBottom="5dp"> 
    </LinearLayout> 

</LinearLayout> 

<ImageButton 
android:id="@+id/back_btn" 
android:layout_width="30dp" 
android:layout_height="190dp" 
android:layout_alignParentLeft="true" 
android:layout_centerVertical="true" 
android:layout_marginLeft="-5dp" 
android:background="@drawable/button_movielist_back" 
/> 

</RelativeLayout> 
+0

雅改正的,你能告訴我怎麼改? – String 2013-03-28 11:10:48

+0

是的,我可以告訴你,如果你告訴我什麼類型的佈局是理想的?一個草圖或其他東西.. – 2013-03-28 11:13:12

+0

我想放置在這個佈局與水平滾動大尺寸圖像 – String 2013-03-28 11:15:20