2016-02-20 117 views
0

我在我的佈局中使用了一個CheckBox這部分是可見的。我包括截圖。複選框部分可見

下面是佈局和java代碼。

的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); 
       } 
      } 
     }); 

截圖:

+0

change android:layout_width =「wrap_content」 android:layout_height =「wrap_content」 –

回答

1

android:layout_widthandroid:layout_height太小,他們更改爲"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" /> 
1

記住OnCheckedChangeListener調用一次,當你運行applicatiom。 然後,嘗試設置不同的大小。也許20dp太小了。