2016-08-22 3 views
0

私はいくつかのビューを含む基本レイアウトを持っています。ネットワーク接続があると、RecyclerViewが表示されます。ユーザーがスワイプしてリフレッシュし、接続がない場合、ボタンとテキストビューが最初の場所では見えない基本レイアウト内に表示されます。問題は、Androidバージョン< Lollilopを搭載した端末でボタンをクリックできないことです。バージョンではボタンをクリックできません<Lollipop

basic_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/listSurveysRlt" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

<com.rey.material.widget.TextView 
    android:id="@+id/codeDescTtv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingBottom="@dimen/code_dest_txv_padding_bottom" 
    android:visibility="gone" 
    android:gravity="center" 
    android:layout_above="@+id/sRetryBtn" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" 
    android:textSize="@dimen/code_dest_txv_text_size" 
    android:textColor="@android:color/black" 
    android:textStyle="bold" /> 

<com.rey.material.widget.Button 
    android:id="@+id/sRetryBtn" 
    android:layout_width="@dimen/action_btn_width" 
    android:layout_height="@dimen/action_btn_height" 
    android:text="@string/retry" 
    android:textColor="@android:color/white" 
    android:background="@drawable/ripple_drawable" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" 
    android:visibility="gone" /> 

<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/swipeRefreshLlt" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/completedSurveysRcV" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="@dimen/surveys_rcv_margin_top" /> 

</android.support.v4.widget.SwipeRefreshLayout> 

<ImageView 
    android:id="@+id/noSurveysImv" 
    android:layout_width="@dimen/no_surveys_imv_width" 
    android:layout_height="@dimen/no_surveys_imv_height" 
    android:src="@drawable/no_surveys" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="@dimen/no_surveys_imv_margin_top" 
    android:visibility="gone" 
    android:contentDescription="@string/ongoing" /> 

<com.rey.material.widget.TextView 
    android:id="@+id/noSurveysTxv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/noSurveysImv" 
    android:text="@string/no_completed" 
    android:textSize="@dimen/no_surveys_txv_text_size" 
    android:textColor="@color/no_surveys_txv_color" 
    android:visibility="gone" 
    android:layout_centerHorizontal="true" /> 

</RelativeLayout> 

不可視に見え、またその逆からcorrenspondingビューを変換する方法:

private void onErrorBackgroundView(int code) { 
    listSurveysRlt.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.view_color)); 
    completedSurveysRcV.setVisibility(View.GONE); //RecyclerView 
    codeDescTtv.setVisibility(View.VISIBLE); //TextView 
    retryBtn.setVisibility(View.VISIBLE); //not clickable button 
    codeDescTtv.setText(getResources().getString(inputValidationCodes.get(code))); 
} 
+0

'retryBtn.setEnabled(true);'も指定しようとしましたか? – Salem

+0

ボタンにクリックリスナーを追加するコードはどこですか? – dweebo

答えて

0

一部掘削私はこの奇妙な行動の背後にある理由を発見した後にフレームワーク。原因はUIのクリックをブロックするSwipeRefreshLayoutであったため、ユーザーが画面をスワイプして接続が利用可能になったときに可視性を復元するたびに、このレイアウトの表示を消すように設定することで問題を解決しました。なぜ誰かがこれがバージョン< Lollipopで起こっていたのを知っていれば、大いに役立つだろう。

関連する問題