我有LinearLayout
FrameLayout
中的视图。这个LinearLayout
位于框架的顶部。
在此LinearLayout
中,有一些TextView
可点击。当我将LinearLayout
设置为View.GONE
时,一切都会按预期消失,但TextView仍然可以点击。
这是为什么?除了将所有可点击的TextView
设置为View.GONE
之外,我该如何避免呢?
XML
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/match_settings_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#40c0a9"
android:visibility="gone"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textSize="20sp"
android:textColor="#fff"
android:text="@string/lbl_age" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontBoldTextView
android:id="@+id/age_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/white_rounded_bg"
android:padding="6dp"
android:textSize="20sp"
android:textColor="#0099cb"
android:text="18 to 99" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textSize="20sp"
android:textColor="#fff"
android:text="@string/lbl_location" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontBoldTextView
android:id="@+id/location_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/white_rounded_bg"
android:padding="6dp"
android:textSize="20sp"
android:textColor="#0099cb"
android:text="Any Distance" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
活动
// Handles expanding match settings window
final ToggleButton btnShowMatchSettings = (ToggleButton) findViewById(R.id.btn_show_match_settings);
btnShowMatchSettings.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
LinearLayout container = (LinearLayout) findViewById(R.id.match_settings_container);
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
btnShowMatchSettings.setBackgroundResource(R.drawable.ico_menu_open);
container.setAnimation(AnimationUtils.loadAnimation(DashboardActivity.this, R.anim.slide_down));
container.setVisibility(View.VISIBLE);
ageSetting = (CustomFontBoldTextView) findViewById(R.id.age_setting);
ageSetting.setVisibility(View.VISIBLE);
ageSetting.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new AgePickerDialog().show(getFragmentManager(), "agePicker");
}
});
locationSetting = (CustomFontBoldTextView) findViewById(R.id.location_setting);
locationSetting.setVisibility(View.VISIBLE);
locationSetting.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new LocationPickerDialog().show(getFragmentManager(), "locationPicker");
}
});
}
else {
btnShowMatchSettings.setBackgroundResource(R.drawable.ico_menu);
container.setAnimation(AnimationUtils.loadAnimation(DashboardActivity.this, R.anim.slide_up));
container.setVisibility(View.GONE);
ageSetting.setVisibility(View.GONE);
locationSetting.setVisibility(View.GONE);
}
}
});
}
答案 0 :(得分:1)
更改视图的可见性这一事实并不意味着它们已被销毁。 你应该尝试添加这样的东西
yourButton.setClickable(false);