2016-04-22 25 views
1

予加載偏好篩選具有以下佈置:按鈕經過在ICS和果凍豆(API一十六分之十五)一個偏好的ListView

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/export_main_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="?android:attr/windowBackground" 
    android:clickable="true"> 

    <ImageView 
     android:id="@+id/export_background" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:contentDescription="@string/entry_background" /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/export_settings_list" 
     android:scrollbars="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clipToPadding="false"/> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/export_fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/ic_file_upload_white_24" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentBottom="true" 
     android:clickable="true"/> 

</RelativeLayout> 

的RecyclerView是其中一個XML文件的偏好被充氣列表。佈局的其餘部分,FAB和ImageView,只是添加了自定義首選項屏幕。

所有這些在最新的Android版本上都能很好地工作,但在ICS和Jelly Bean上(我沒有嘗試Kikat),FloatingActionButton無法獲得任何點擊並變得有點透明。

我嘗試了十幾種不同的東西(使用標準按鈕,標準lisview等),但該按鈕在屏幕上仍然無用,下面的列表項總是被點擊。

我認爲這個問題可能來自於我膨脹XML偏好文件的事實,因爲我使用標準列表創建了相同的佈局,並且該按鈕在任何版本中運行良好。

最壞的情況,我將只需要加載一個具體佈局爲舊版本...

回答

1

其實我終於成功,使其工作。

在我的問題中,我是從XML中添加按鈕,但無法捕獲點擊事件。我終於改變了我的代碼,並在佈局中動態地添加了按鈕,並且它工作正常!

我仍然無法解釋爲什麼當按鈕被以編程方式添加,可能與該按鈕保持列表下方的XML的點擊是可能的...

反正這裏的代碼:

final ViewGroup innerContainer = (ViewGroup) exportView.findViewById(R.id.export_main_frame); 
    final View innerView = super.onCreateView(inflater, innerContainer, savedInstanceState); 
    if (innerView != null) { 
     innerContainer.addView(innerView); 

     // Add dynamically the FAB to export 
     FloatingActionButton dynamicExportFAB = new FloatingActionButton(getActivity()); 
     dynamicExportFAB.setImageResource(R.drawable.ic_file_upload_white_24); 
     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
     params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
     params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
     params.addRule(RelativeLayout.ALIGN_PARENT_END); 

     dynamicExportFAB.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       //TODO 
      } 
     }); 

     innerContainer.addView(dynamicExportFAB, params); 
    }