开发者

Android EditText problems

i have created an EditText like this

<RelativeLayout>
  <TableLayout>
    <TableRow>
    <EditText android:id="@+id/myid" 
              android:hint="This is my hint"
              android:textColorHint = "@color/white"
              android:layout_height="wrap_content" 
              android:layout_width="wrap_content"
              android:gravity="center"
              android:textSize = "20sp"
              android:textColor = "@color/white"
              android:textStyle = "bold"
              android:background ="@drawable/mybackgroundimage"
              android:fitsSystemWindows  = "true"
              android:includeFontPadding = "true"
              android:singleLine="true" 
              android:cursorVisible = "false"

              >
    </EditText>
    </TableRow>
</TableLayout>

Its in a table layout. i have 2 problems

  1. As soon as i remove android:gravity="center" hints shows but i need to show text from centre and show hints in edit text as well(Is it a bug in android sdk?).

  2. i like to wrap text up-to a certain size if texts grows larger than textview bounds.Right now it goes beyond the view and doest not shows the entered digits af开发者_运维百科ter its ending but digits keeps on getting added in edit text.

Please if anyone have any idea how to do this.

Thanks


To show all the text in the EditText just add:

android:scrollHorizontally="true"

As soon as i remove android:gravity="center" hints shows but i need to show text from centre and show hints in edit text as well(Is it a bug in android sdk?).

I don't understand what you mean at the fist point. Can you explain it to me?


  1. (if i understand the question)android:gravity="center" allways refear to the "son" of the view. the "son" of the EditText is the text. If you want to put the EditText in the center and the text in the center you should put other gravity=center in the tablerow.

  2. You should change the size of the text programatically:

    if (myid.getText().toString().lengh()> XX )
    myid.setTextSize("xxdip")

    Or something like this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜