2017-11-03 4 views
0

Ich erstelle ein Formular, in dem ich einige EditText und einige TextView angegeben habe. Endlich habe ich eine Checkbox wie folgt angegeben:Checkbox wird nicht angezeigt

<CheckBox 
       android:id="@+id/sendAsSMS" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send As SMS" 
       android:checked="false" 
       android:textSize="16sp" 

       /> 

Aber dieses Kontrollkästchen nicht im Layout angezeigt wurden, wenn die App läuft. Was läuft hier falsch? Meine volle layout.xml ist:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.schoolcounter.ui.activity.teacher.AddHomeworkActivity"> 

    <LinearLayout 
     android:id="@+id/addHomeworkForm" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="16dp"> 

     <LinearLayout 
      android:id="@+id/selectClassLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/select_class" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="end" 
       android:paddingRight="@dimen/text_padding" 
       android:paddingTop="@dimen/text_padding" 
       android:paddingBottom="@dimen/text_padding" 
       android:text="@string/select_class" 
       android:textAlignment="textEnd" 
       android:textColor="@color/colorPrimary" 
       android:textStyle="bold" 
       android:textSize="@dimen/text_size" /> 

      <com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner 
       android:id="@+id/select_class_spinner" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="start" 
       android:hint="@string/select_class" 
       android:textAlignment="viewStart" 
       android:textColorHint="@color/colorHint" 
       android:textSize="@dimen/text_size" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/selectSectionLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/select_section" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="end" 
       android:paddingRight="@dimen/text_padding" 
       android:paddingTop="@dimen/text_padding" 
       android:paddingBottom="@dimen/text_padding" 
       android:text="@string/select_section" 
       android:textAlignment="textEnd" 
       android:textColor="@color/colorPrimary" 
       android:textSize="@dimen/text_size" 
       android:textStyle="bold"/> 

      <com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner 
       android:id="@+id/select_section_spinner" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="start" 
       android:hint="@string/select_section" 
       android:textAlignment="viewStart" 
       android:textColorHint="@color/colorHint" 
       android:textSize="@dimen/text_size"/> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/selectSubjectLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/select_subject" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="end" 
       android:paddingRight="@dimen/text_padding" 
       android:paddingTop="@dimen/text_padding" 
       android:paddingBottom="@dimen/text_padding" 
       android:text="@string/select_subject" 
       android:textAlignment="textEnd" 
       android:textColor="@color/colorPrimary" 
       android:textSize="@dimen/text_size" 
       android:textStyle="bold"/> 

      <com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner 
       android:id="@+id/select_subject_spinner" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="start" 
       android:hint="@string/select_subject" 
       android:textAlignment="viewStart" 
       android:textColorHint="@color/colorHint" 
       android:textSize="@dimen/text_size"/> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/uploadedDateLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/textView_uploaded_date" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="end" 
       android:paddingRight="@dimen/text_padding" 
       android:paddingTop="@dimen/text_padding" 
       android:paddingBottom="@dimen/text_padding" 
       android:text="@string/text_uploaded_date" 
       android:textAlignment="textEnd" 
       android:textColor="@color/colorPrimary" 
       android:textSize="@dimen/text_size" 
       android:textStyle="bold"/> 

      <EditText 
       android:id="@+id/editTextUploadedDate" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:textSize="@dimen/text_size" 
       android:focusable="false" 
       android:focusableInTouchMode="false"/> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/completionDateLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/textView_completion_date" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="end" 
       android:paddingRight="@dimen/text_padding" 
       android:paddingTop="@dimen/text_padding" 
       android:paddingBottom="@dimen/text_padding" 
       android:text="@string/text_completion_date" 
       android:textAlignment="textEnd" 
       android:textColor="@color/colorPrimary" 
       android:textSize="@dimen/text_size" 
       android:textStyle="bold"/> 

      <EditText 
       android:id="@+id/editTextCompletionDate" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:textSize="@dimen/text_size" 
       android:focusable="false" 
       android:focusableInTouchMode="false"/> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/textView_Homework" 
       android:text="@string/text_homework" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="@dimen/text_padding" 
       android:textColor="@color/colorPrimary" 
       android:textSize="@dimen/text_size" 
       android:textStyle="bold"/> 

      <EditText 
       android:id="@+id/editTextHomeworkText" 
       android:layout_width="match_parent" 
       android:layout_height="74dp" 
       android:ems="10" 
       android:inputType="textMultiLine" 
       android:textSize="@dimen/text_size"/> 

      <CheckBox 
       android:id="@+id/sendAsSMS" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send As SMS" 
       android:checked="false" 
       android:textSize="16sp" 

       /> 


     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:orientation="vertical" 
      android:weightSum="1"> 


      <Button 
       android:id="@+id/uploadHomeworkButton" 
       style="@style/button_style_corners" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="50dp" 
       android:layout_marginRight="50dp" 
       android:layout_marginBottom="16dp" 
       android:layout_marginTop="16dp" 
       android:text="@string/text_upload" 
       android:textAlignment="center" 
       android:textColor="@color/colorWhite" /> 

     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

Antwort

1

Sie haben die Breite Attributwert von EditText 'editTextHomeworkText' in

 <TextView 
      android:id="@+id/textView_Homework" 
      android:text="@string/text_homework" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="@dimen/text_padding" 
      android:textColor="@color/colorPrimary" 
      android:textSize="@dimen/text_size" 
      android:textStyle="bold"/> 

     <EditText 
      android:id="@+id/editTextHomeworkText" 
      android:layout_width="match_parent" 
      android:layout_height="74dp" 
      android:ems="10" 
      android:inputType="textMultiLine" 
      android:textSize="@dimen/text_size"/> 

     <CheckBox 
      android:id="@+id/sendAsSMS" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Send As SMS" 
      android:checked="false" 
      android:textSize="16sp" 

      /> 


    </LinearLayout> 

Da Sie die Breite Wert zugewiesen ändern als 'match_parent' wird der gesamte verbleibende Speicherplatz nur von EditText abgedeckt. Hier können Sie entweder den Wert ‚wrap_content‘ ändern oder tun es wie

  android:layout_width="0dp" 
      android:layout_weight="1" 
Verwandte Themen