Android:键盘与EditText重叠(带有printscreens)

前端之家收集整理的这篇文章主要介绍了Android:键盘与EditText重叠(带有printscreens)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个EditText(用户可以输入数字),
所以当用户点击EditText文本框时,会打开一个带数字的键盘.

如您所见,键盘隐藏了文本框的一小部分.

但是当我按下一个键,例如0时,它看起来没问题.

有什么我可以做的(除了把EditText更高)所以它看起来像在第二张图片中?

编辑:.xml代码

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:orientation="vertical"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent" android:weightSum="1">
  7. <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content">
  8. <LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentRight="true">
  9. <android.widget.CheckedTextView android:id="@+id/checkedTextView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp" android:text="@string/toString"></android.widget.CheckedTextView>
  10. <AutoCompleteTextView android:layout_height="wrap_content" android:id="@+id/autoCompleteTextView1" android:layout_width="fill_parent" android:text="@string/emptyString" android:textSize="17sp" android:gravity="top|left" android:minHeight="62dp">
  11. <requestFocus></requestFocus>
  12. </AutoCompleteTextView>
  13. <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2">
  14. <Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.33333333333" android:text="@string/contactsString" android:textSize="17sp" android:id="@+id/contactsButton"></Button>
  15. <Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="@string/groupsString" android:layout_width="fill_parent" android:id="@+id/groupsButton" android:textSize="17sp"></Button>
  16. <Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="@string/favouritesString" android:layout_width="fill_parent" android:id="@+id/button3" android:textSize="17sp"></Button>
  17. </LinearLayout>
  18. <TextView android:id="@+id/textView1" android:text="@string/messageString" android:layout_height="wrap_content" android:textSize="17sp" android:layout_width="fill_parent"></TextView>
  19. <EditText android:layout_height="wrap_content" android:id="@+id/editText1" android:layout_width="fill_parent" android:gravity="top|left" android:minHeight="105dp"></EditText>
  20. <TextView android:id="@+id/textView2" android:text="@string/repetition" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp"></TextView>
  21. <Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/spinner"></Spinner>
  22. <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout3" android:layout_width="fill_parent">
  23. <ImageView android:src="@drawable/button_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_weight="0.1"></ImageView>
  24. <EditText android:layout_height="wrap_content" android:id="@+id/timeET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4"></EditText>
  25. <ImageView android:src="@drawable/button_date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView2" android:layout_weight="0.1"></ImageView>
  26. <EditText android:layout_height="wrap_content" android:id="@+id/dateET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText>
  27. </LinearLayout>
  28. <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent">
  29. <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/linearLayout4" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentLeft="true">
  30. <Button android:layout_weight="0.5" android:layout_height="wrap_content" android:text="@string/button_ok" android:layout_width="fill_parent" android:id="@+id/button4" android:textSize="17sp"></Button>
  31. <Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/button5" android:layout_weight="0.5" android:text="@string/button_cancel" android:textSize="17sp"></Button>
  32. </LinearLayout>
  33. </RelativeLayout>
  34. </LinearLayout>
  35. </RelativeLayout>
  36.  
  37. </LinearLayout>

解决方法

我已经尝试过你的XML,是的,你说得对,问题就出现了.

为了解决这个问题,我在MainActivity.java中编写了这一行,希望对您有所帮助,并将布局XML放在ScrollView中.

活动

  1. public void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. setContentView(R.layout.temp);
  4. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  5.  
  6. final EditText time = (EditText)findViewById(R.id.timeET);
  7. time.setOnTouchListener(new OnTouchListener() {
  8.  
  9. public boolean onTouch(View v,MotionEvent event) {
  10. time.requestLayout();
  11. MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
  12.  
  13. return false;
  14. }
  15. });
  16. final EditText date = (EditText)findViewById(R.id.dateET);
  17. date.setOnTouchListener(new OnTouchListener() {
  18.  
  19. public boolean onTouch(View v,MotionEvent event) {
  20. time.requestLayout();
  21. MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
  22.  
  23. return false;
  24. }
  25. });
  26. }

而XML就像,

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:orientation="vertical"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent" >
  7.  
  8. <ScrollView android:id="@+id/scrollView1"
  9. android:layout_height="fill_parent"
  10. android:layout_width="fill_parent"
  11. android:weightSum="1">
  12. ---
  13. ---
  14. ---
  15. </ScrollView>
  16. </LinearLayout>

猜你在找的Android相关文章