java - 键盘无法抬起编辑文本,因为scrollview

标签 java android

当键盘上升时,她超出了 textView 而是拿起它(拿起所有的 linearLayout )

你可以在我的代码中看到它 正如我所说,键盘覆盖了 textView

<TextView
    android:id="@+id/cvsTvHeader"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="368dp" >

        <LinearLayout
            android:id="@+id/cvsLlVerticalScrollView"
            android:layout_width="match_parent"
            android:layout_height="274dp"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/cvsEtPost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.07"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/cvsBtuSendPost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

公共(public)类 ConversationActivity 扩展 Activity {

myApp app;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_conversation);
    app = (myApp)getApplication();

    setHeaderText();
    sendPost();
}

public boolean onInterceptTouchEvent(MotionEvent ev)
{
    onTouchEvent(ev);
    return false;
}

private void setHeaderText() {

    TextView tv =(TextView)findViewById(R.id.cvsTvHeader);
    String text = app.bar.arrPostsObj.get(app.indexPostObjInArrPostObj).post;
    tv.setText(text);

}

private void sendPost() {

    Button btu =(Button)findViewById(R.id.cvsBtuSendPost);
    btu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            addpost();

        }
    });

}

public void addpost() {

       EditText et = getPostText();
       if (et != null) {

           String text = et.getText().toString();
           int i = 0;
        if (text != null && text.length() > 0) {

            for ( i = 0; i < text.length(); i++) {

                char c = text.charAt(i);
                if (c != ' ') {
                    break;
                }
            }

            if (i < text.length()) {
                final TextView tv = new TextView(this);

                tv.setText(text);
                tv.setTextSize(30);
                LinearLayout ll = new LinearLayout(this);

                tv.setId(app.arrPostLls.size());

                    ll.setOrientation(LinearLayout.VERTICAL);
                    ll.addView(tv); //ll.addView(tv, index)
                    LinearLayout llL =(LinearLayout)findViewById(R.id.cvsLlVerticalScrollView);
                    llL.addView(ll);
                    app.arrPostLls.add(ll);


            }

        }

        finishPost(0, null, et, false, false);

    }


}

private EditText getPostText() {

    EditText et =(EditText)findViewById(R.id.cvsEtPost);

    return et;

}

private void finishPost(int index,PostObject postObject,EditText et,boolean boolNewPost,boolean boolGFather) {

    et.setText("");
    InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(et.getWindowToken(), 0); 

}

最佳答案

在这种情况下,您需要将 Root View 作为 ScrollView ,

        <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/cvsTvHeader"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <ScrollView
                    android:id="@+id/scrollView1"
                    android:layout_width="match_parent"
                    android:layout_height="368dp"
                    android:background="@android:color/holo_purple" >

                    <!-- android:windowSoftInputMode="adjustPan|adjustResize" -->

                    <LinearLayout
                        android:id="@+id/cvsLlVerticalScrollView"
                        android:layout_width="match_parent"
                        android:layout_height="274dp"
                        android:orientation="vertical" >
                    </LinearLayout>
                </ScrollView>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <EditText
                    android:id="@+id/cvsEtPost"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.07"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <Button
                    android:id="@+id/cvsBtuSendPost"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Button" />
            </LinearLayout>
        </LinearLayout>

    </ScrollView>

关于java - 键盘无法抬起编辑文本,因为scrollview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26200007/

相关文章:

java - i18n 用于静态 html 内容

java - JNDI Active Directory,创建具有作用域的组

Android onReceive 未调用

java - 如何让通知播放声音?

java - 尝试遵循之前关于如何创建动画的答案,但它完全消失了

JavaFX 应用程序在调用 Stage.ShowAndWait() 方法时导致 Ubuntu 14.04 上的 Java VM 崩溃,出现问题帧 : C [libc. so.6+0x3c10d]

简历上的 Java android Listview 显示所选项目

java - 未在 RCP 产品中加载透视图和 View 的图像

android - 与服务器的连接丢失时在 Android 上备份数据的最佳方法

android - Dex 文件布局 - method_handles 和 call_site_ids 部分的偏移量和大小