2012-10-03 37 views
0

我有一個編輯文本,當我給它設置一個提示時會變得很奇怪。提示行爲怪異

XML:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dip" 
    android:layout_marginLeft="5dip" 
    android:layout_marginTop="8dip" 
    android:background="@android:drawable/edit_text" 
    android:baselineAligned="false" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" 
    android:paddingRight="0dip" > 

    <EditText 
     android:id="@+id/pinDisplay" 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.85" 
     android:background="@null" 
     /> 

    <ImageButton 
     android:id="@+id/backspace" 
     style="@android:style/Widget.Button" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center_vertical" 
     android:layout_marginBottom="2dip" 
     android:layout_marginRight="8dip" 
     android:layout_marginTop="2dip" 
     android:layout_weight="0.15" 
     android:gravity="center" 
     android:src="@android:drawable/ic_input_delete" /> 
</LinearLayout> 

代碼:

private float hintTextSize = 24; 

private void initializeInputText() { 
    input = (EditText) findViewById(R.id.pinDisplay); 
    input.setInputType(InputType.TYPE_NULL); 
    input.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
    input.setTextSize(TypedValue.COMPLEX_UNIT_SP, hintTextSize); 
    input.setHint("Kies pincode"); 
    input.setCursorVisible(false); 

    input.setOnTouchListener(new OnTouchListener() { 
     public boolean onTouch(View arg0, MotionEvent arg1) { 
      return true; 
     } 
    }); 

    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLengthInput) }); 
    input.addTextChangedListener(new TextWatcher() { 

     public void onTextChanged(CharSequence s, int start, int before, 
       int count) { 
      input.setError(null); 

      if (s.length() >= maxLengthInput) { 
       input.setCursorVisible(false); 
       btnOk.setEnabled(true); 
       btnOk.setTextColor(Color.parseColor("#00B32D")); //Green 
      } else { 
       btnOk.setEnabled(false); 
       btnOk.setTextColor(Color.parseColor("#B8B8B8")); //Light gray 
       input.setCursorVisible(true); 
       input.setSelection(input.getText().length()); 
      } 
     } 

     public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) { 
     } 

     public void afterTextChanged(Editable s) { 
      if (!input.getText().toString().equals("")) { 
       input.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); 
      } else { 
       input.setTextSize(TypedValue.COMPLEX_UNIT_SP, hintTextSize); 
      } 
     } 
    }); 
} 

這是第一個:

enter image description here

但是當我添加了許多的EditText上的增長,並採取了很多空間。

enter image description here

什麼可以原因?

+0

你嘗試設置你的'EditText'的填充在你的XML?這是第二個屏幕上的變化。 –

+0

我剛剛設置爲0dp,但這不會改變任何內容。 –

回答

1

只是刪除下面的代碼在類:

  input.setTextSize(TypedValue.COMPLEX_UNIT_SP, hintTextSize); 

,並嘗試