我想根據複選框首選項顯示相對佈局。現在,無論複選框處於何種狀態,佈局都消失了。爲什麼我的setVisibility視圖不能正確顯示?
final RelativeLayout unreadCount = (RelativeLayout) findViewById(R.id.header_navigation);
if(_preferences.getBoolean(UNREAD_COUNT_ENABLED_KEY, false)){
unreadCount.setVisibility(View.VISIBLE);
}else{
if(_preferences.getBoolean(UNREAD_COUNT_ENABLED_KEY, true)){
unreadCount.setVisibility(View.GONE);
}
}
<RelativeLayout
android:id="@+id/header_navigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp">
<Button
android:id="@+id/previous_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:hapticFeedbackEnabled="true"
android:background="@drawable/btn_prev_arrow" />
<TextView
android:id="@+id/notification_count_text_view"
android:layout_height="50dip"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/previous_button"
android:layout_toLeftOf="@+id/next_button"
android:gravity="center"
android:focusable="true"
android:clickable="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:text="0/0"/>
<Button
android:id="@+id/next_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:hapticFeedbackEnabled="true"
android:background="@drawable/btn_next_arrow"/>
</RelativeLayout>
您是否已將代碼放入調試中以確保它完全進入if語句?另外,在XML中設置的可見性屬性是什麼? – hooked82
@ hooked82我的if語句正在工作,並且我嘗試在我的佈局中將可見性屬性設置爲「可見」,但沒有任何更改。 – adneal