を生成し、私はこのレイアウトの例があります。アンドロイド:ScrollView内部の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用タッチのリスナーに追加することができます!フレームアウト "action_bar_layout"は、常に下に存在する必要があります – anthony
私はあなたを取得していない、あなたは精巧にお祈りください... –