2016-09-21 60 views
0

我正在嘗試與微調工作。我還有其他意見。所有其他視圖都顯示並且工作正常,除了微調。執行後,微調器根本不可見。然而,它在設計模式下顯示,但不是在執行時顯示。微調不會顯示在運行應用程序

我的XML是如下:

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/background" 
    tools:context="com.example.kc.sample.HomePage"> 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:gravity="center"> 

      <android.support.design.widget.TextInputLayout 
       style="@style/fontStyle" 
       android:id="@+id/input_layout_registerName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="30dp"> 
       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="40dp" 
        android:inputType="textCapSentences" 
        android:textSize="15dp" 
        android:paddingStart="@dimen/activity_horizontal_margin" 
        android:textColor="#274A72" 
        android:id="@+id/editRegisterName" 
        android:hint="@string/Name" 
        android:singleLine="true" 
        android:background="@drawable/edit_text_border" 
        android:lines="1" 
        android:maxLength="64"/> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       style="@style/fontStyle" 
       android:id="@+id/input_layout_registerDOB" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="40dp" 
        android:inputType="textCapSentences" 
        android:textSize="15dp" 
        android:paddingStart="@dimen/activity_horizontal_margin" 
        android:focusableInTouchMode="false" 
        android:textColor="#274A72" 
        android:id="@+id/editRegisterDOB" 
        android:hint="@string/DOB" 
        android:singleLine="true" 
        android:background="@drawable/edit_text_border" 
        android:lines="1" 
        android:maxLength="64"/> 
      </android.support.design.widget.TextInputLayout> 

      <TableLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:stretchColumns="*" 
       android:shrinkColumns="*"> 
       <TableRow> 
        <android.support.design.widget.TextInputLayout 
         style="@style/fontStyle" 
         android:id="@+id/input_layout_GenderMale" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1"> 
         <RadioButton 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:textSize="15dp" 
          android:paddingStart="@dimen/activity_horizontal_margin" 
          android:textColor="#274A72" 
          android:id="@+id/radioGenderMale" 
          android:text="@string/Male" 
          android:background="@drawable/edit_text_border" 
          android:onClick="checkMaleMethod" 
         /> 
        </android.support.design.widget.TextInputLayout> 

        <android.support.design.widget.TextInputLayout 
         style="@style/fontStyle" 
         android:id="@+id/input_layout_GenderFemale" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1"> 
         <RadioButton 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:layout_marginRight="10dp" 
          android:textSize="15dp" 
          android:paddingStart="@dimen/activity_horizontal_margin" 
          android:textColor="#274A72" 
          android:id="@+id/radioGenderFemale" 
          android:text="@string/Female" 
          android:background="@drawable/edit_text_border" 
          android:onClick="checkFemaleMethod" 
         /> 
        </android.support.design.widget.TextInputLayout> 
       </TableRow> 
      </TableLayout> 

      <android.support.design.widget.TextInputLayout 
       style="@style/fontStyle" 
       android:id="@+id/input_layout_registerEmail" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="40dp" 
        android:inputType="textCapSentences" 
        android:textSize="15dp" 
        android:paddingStart="@dimen/activity_horizontal_margin" 
        android:textColor="#274A72" 
        android:id="@+id/editRegisterEmail" 
        android:hint="@string/email" 
        android:singleLine="true" 
        android:background="@drawable/edit_text_border" 
        android:lines="1" 
        android:maxLength="64"/> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       style="@style/fontStyle" 
       android:id="@+id/input_layout_registerMobile" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
       <EditText 
        android:layout_width="match_parent" 
        android:inputType="number" 
        android:layout_height="40dp" 
        android:id="@+id/editRegisterPhone" 
        android:textSize="15dp" 
        android:paddingStart="@dimen/activity_horizontal_margin" 
        android:textColor="#274A72" 
        android:hint="@string/Phone" 
        android:singleLine="true" 
        android:background="@drawable/edit_text_border" 
        android:lines="1" 
        android:maxLength="10"/> 
      </android.support.design.widget.TextInputLayout> 

      <TableLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:stretchColumns="*" 
       android:shrinkColumns="*"> 
       <TableRow> 
        <android.support.design.widget.TextInputLayout 
         style="@style/fontStyle" 
         android:id="@+id/input_layout_statusSingle" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1"> 
         <RadioButton 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:textSize="15dp" 
          android:paddingStart="@dimen/activity_horizontal_margin" 
          android:textColor="#274A72" 
          android:id="@+id/radioStatusSingle" 
          android:text="@string/Single" 
          android:background="@drawable/edit_text_border" 
          android:onClick="checkStatusSingleMethod" 
          /> 
        </android.support.design.widget.TextInputLayout> 

        <android.support.design.widget.TextInputLayout 
         style="@style/fontStyle" 
         android:id="@+id/input_layout_statusMarried" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1"> 
         <RadioButton 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:layout_marginRight="10dp" 
          android:textSize="15dp" 
          android:paddingStart="@dimen/activity_horizontal_margin" 
          android:textColor="#274A72" 
          android:id="@+id/radioStatusMarried" 
          android:text="@string/Married" 
          android:background="@drawable/edit_text_border" 
          android:onClick="checkStatusMarriedMethod" 
          /> 
        </android.support.design.widget.TextInputLayout> 
       </TableRow> 
      </TableLayout> 

      <Spinner 
       android:id="@+id/spinner" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:prompt="@string/spinner_title" 
       /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/txtErrorMessage" 
       android:textAlignment="center" 
       android:textSize="15dp" 
       android:textColor="#ff0000"/> 

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

我相應的Java代碼如下:

public class HomePage extends AppCompatActivity implements View.OnClickListener, OnItemSelectedListener { 

    private EditText editName, editDateofBirth, editMail, editMobileNumber, editDate; 
    private RadioButton radioMale, radioFemale, radioStatusSingle, radioStatusMarried; 
    private Button btnPrevious, btnNext; 
    Dialog result; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_home_page); 

     //Few other view declaration here 

     Spinner spinner = (Spinner) findViewById(R.id.spinner); 
     spinner.setOnItemSelectedListener(this); 

     List<String> list = new ArrayList<>(); 
     list.add("One"); 
     list.add("Two"); 
     list.add("Three"); 
     list.add("Four"); 

     ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);   dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     spinner.setAdapter(dataAdapter); 

    } 
@Override 
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { 
     String item = adapterView.getItemAtPosition(i).toString(); 
     Toast.makeText(adapterView.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    public void onNothingSelected(AdapterView<?> adapterView) { 

    } 

如果寫成一個單獨的個人項目同樣微調代碼工作正常,如預期,但包括上述代碼片段中的相同內容在執行時不會顯示微調器。任何人都可以指導我如何使它工作?在此先感謝

回答

0

Fill屬性已過時,使用:

<Spinner 
    android:id="@+id/spinner" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:prompt="@string/spinner_title" 
      /> 
相關問題