2017-05-07 77 views
1

我一直在嘗試添加一個複選框到我的android應用程序的佈局,但它沒有顯示出來。顯示覆選框旁邊的文本字段,但複選框本身保持不可見狀態。這怎麼解決?複選框沒有顯示在Android佈局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.lenovo.myapplication.MainActivity" 
    android:orientation="vertical" 
    android:background="#0000ff" 
    > 

    <EditText 
     android:id="@+id/message" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Write your name" 
     android:textSize="50sp" 
     android:inputType="text" 
     android:layout_margin="16dp" 
    /> 
    <TextView 
     android:layout_margin="16dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Topping" 
     android:textSize="50sp"/> 
    <CheckBox 
     android:layout_width="500sp" 
     android:layout_height="50sp" 
     android:text="new checkbox" 
     android:textSize="50sp" 
     android:scaleX="0.7" 
     android:scaleY="0.7" 
     android:buttonTint="#000000" 
     /> 
</LinearLayout> 
+0

你嘗試運行的代碼?有時您需要清理該項目才能使其工作 – ZeroOne

+0

嘗試將複選框寬度設置爲「包裝內容」並查看結果。 –

+0

@nassertahani將寬度設置爲「wrap_content」 –

回答

2

試試這個複選框XML

<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="new checkbox" 
    android:textSize="16sp" 
    android:scaleX="0.7" 
    android:scaleY="0.7" 
    android:buttonTint="#000000"/>