Reputation: 1527
I am using a CheckBox
in my layout which is partly visible.I am including the screenshot.
Below is the layout and java code.
xml:
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="20dp"
android:layout_height="20dp"
android:text="Check box"
android:id="@+id/checkbox"
android:theme="@style/MyCheckBox"
android:layout_marginRight="40dp"
android:layout_marginTop="20dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
java:
checkbox=(AppCompatCheckBox) findViewById(R.id.checkbox);
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
relativeLayout.setVisibility(View.VISIBLE);
}
else {
relativeLayout.setVisibility(View.INVISIBLE);
}
}
});
Screenshot:
Upvotes: 0
Views: 59
Reputation: 7929
Your android:layout_width
and android:layout_height
are too small, change them to "wrap_content"
:
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check box"
android:id="@+id/checkbox"
android:theme="@style/MyCheckBox"
android:layout_marginRight="40dp"
android:layout_marginTop="20dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
Upvotes: 1
Reputation: 196
Remember that OnCheckedChangeListener is called one time when you run applicatiom. Then, try to set different size. Maybe 20dp is too small.
Upvotes: 1