2011-02-09 10 views
0

화면에 표시되고 있지만 클릭 할 수없는 버튼에 이상한 문제가 있습니다. onClick 이벤트가 발생하지 않는 것은 아니며, 클릭 레이어에 투명 레이어가있는 것처럼 물리적으로 클릭에 반응하지 않는 것처럼 보입니다. 버튼을 클릭 할 수 없음

주가에 내장되어 Activity :

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/th_set_menu_tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"/> 
    <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:paddingTop="65px"> 

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/media_item_tab" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
       <TextView 
       android:id="@+id/media_title" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textSize="30sp" 
       android:textColor="#40A5D9" 
       android:gravity="center" 
       android:layout_alignParentTop="true" 
       android:singleLine="true" 
       android:ellipsize="marquee" 
       android:text="Title" 
       > 
       </TextView> 
       <ImageView 
       android:id="@+id/media_cover" 
       android:layout_width="fill_parent" 
       android:layout_height="180px" 
       android:gravity="center" 
       android:layout_below="@+id/media_title" 
       android:src="@drawable/geniocover"    
       > 
       </ImageView> 
       <TextView 
       android:id="@+id/media_author" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textSize="20sp" 
       android:textColor="#86CCF3" 
       android:gravity="center" 
       android:singleLine="true" 
       android:ellipsize="marquee" 
       android:layout_below="@+id/media_cover" 
       android:text="Author" 
       > 
       </TextView> 
       <TextView 
       android:id="@+id/media_album" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:textColor="#DAFFFF" 
       android:gravity="center" 
       android:singleLine="true" 
       android:ellipsize="marquee" 
       android:layout_below="@+id/media_author"  
       android:text="Album (Year)" 
       > 
       </TextView> 
       <Button 
       android:id="@+id/play_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Play" 
       android:textColor="#003983" 
       android:textStyle="bold" 
       android:textSize="20sp" 
       android:gravity="center" 
       android:layout_below="@+id/media_album" 
       android:clickable="true"  
       > 
       </Button> 
      </RelativeLayout> 
      <ListView 
      android:id = "@+id/tablist" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      /> 
    </FrameLayout> 
</TabHost> 

어떤 제안 : 화면에 완벽하게 표시됩니다

public class MusicList extends Activity implements OnClickListener { 
... 
@Override 
    public void onCreate(Bundle bundle) 
    { 
     super.onCreate(bundle);  

     setContentView(R.layout.mymusic); 
     this.myTabHost = (TabHost)this.findViewById(R.id.th_set_menu_tabhost); 
     this.myTabHost.setup(); 

     TabSpec ts = myTabHost.newTabSpec("TAB_TAG_1"); 

     ts.setIndicator("Media Item",getResources().getDrawable(R.drawable.music));    

     ts.setContent(R.id.media_item_tab); 

     try { 
      relativeLayout = (RelativeLayout) myTabHost.findViewById(android.R.id.tabcontent).findViewById(R.id.media_item_tab); 
     } catch (NullPointerException e) { 
      Log.e(this.getClass().getSimpleName(),"Layout is not correct",e); 
     } 

      Button button = (Button)relativeLayout.findViewById(R.id.play_button); 
      // button.setClickable(true); 
      button.setOnClickListener(this); 
        myTabHost.addTab(ts); 
    } 
    @Override 
    public void onClick(View v) { 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(itemData.get("ITEM_URL")))); 
    } 
} 

배치는이처럼?

감사합니다.

+0

궁금합니다. 모든 요소가 이전보다 아래에있을 때 RelativeLayout을 사용하는 이유는 무엇입니까? orientation = vertical 인 LinearLayout도 마찬가지로 할 수 있습니까? –

+0

글쎄, 현재 레이아웃은 단순히 우리가 작업하고있는 모형이기 때문에 첫 번째 상태 (실제로 RelativeLayout 일 때)와 몇 가지 변화가있었습니다. 이것을 문제의 근원으로 간주하기 위해 이것을 바꾸려고 노력할 것입니다. –

+0

당신이 말하길 * onClick 이벤트가 발생하지 않는 것은 아니지만 주석에 * 입력하지 않는 것이 보입니다. 나는 혼란스러워. – Nanne

답변

1

FrameLayout에는 두 명으로 구성된 호스트가 있습니다. ListView가 마지막으로 추가되어 맨 위에 표시되며 입력 사항이 모두 접수되었습니다.

+0

그것은 일했다! 레이아웃 xml의 순서가 고려되었지만 어쨌든 내 문제가 해결되었습니다. 감사합니다! –

0

이 문제는 tablayout의 복잡한 구조 때문에 발생한다고 생각합니다.

일반적으로 TabLayout을 보유한 별도의 액티비티를 사용하고 다른 액티비티를 내용으로 탭 호스트에 넣습니다 (tabSpec.setContent(Intent intent)).

실제로이 방법으로 문제가 해결됩니다.

그런데 LinearLayout을 사용할 수있는 RelativeLayout을 사용하지 마십시오.

+0

두 가지 방법 모두 탭 작성에 유효하므로 여러 탭의 동일한 활동에서 탭 당 하나의 활동으로 이동하는 것이 적절한 해결책이라고 생각하지 않습니다. 아마도 그것을 해결할 것이지만 하나의 단일 활동으로이를 수행 할 수 있습니다. –

관련 문제