我有這樣的佈局實例:安卓的EditText內滾動型:隱藏鍵盤產生奇怪的滾動
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#FFF880"
android:gravity="center_vertical"
android:orientation="horizontal">
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/action_bar_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/emotion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_blue_bright" />
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:inputType="textMultiLine|textCapSentences"
android:singleLine="false"
android:text="On sait depuis longtemps "
android:textColor="@android:color/black" />
<FrameLayout
android:id="@+id/photo"
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="#EE00FF">
</FrameLayout>
</LinearLayout>
</ScrollView>
<FrameLayout
android:id="@+id/action_bar_layout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:background="#990000"
android:gravity="center_vertical"
android:orientation="horizontal">
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
而且我的樣本活動:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edittext);
final ScrollView scrollView = (ScrollView)findViewById(R.id.scroll);
final EditText edittext = (EditText)findViewById(R.id.edit);
// Setup scrollview
scrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_MOVE:
// Hide keyboard
UIUtils.hideKeyboard(edittext, EditTextActivity.this);
break;
}
return false;
}
});
public static void hideKeyboard(View view, Activity activity) {
if (view != null) {
view.clearFocus();
if (activity != null) {
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
InputMethodManager imm = (InputMethodManager) activity.
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}
所以我想Facebook等新的職位相同的行爲:當你想滾動鍵盤時自動消失。
但在我的情況下,當鍵盤被隱藏時想要滾動時會出現奇怪的行爲。
謝謝你們的幫助!
沒有Risbhabh觸摸聽者補充! framelyout「action_bar_layout」必須始終存在於底部 – anthony
我沒有得到你,請你詳細說明...... –