Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当显示软输入时,“向上推”列表视图,而不是条形图_Android_Android Layout_Listview_Window Soft Input Mode_Adjustpan - Fatal编程技术网

Android 当显示软输入时,“向上推”列表视图,而不是条形图

Android 当显示软输入时,“向上推”列表视图,而不是条形图,android,android-layout,listview,window-soft-input-mode,adjustpan,Android,Android Layout,Listview,Window Soft Input Mode,Adjustpan,我在查看寻呼机的页面中有这样的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black"> <LinearLayout

我在查看寻呼机的页面中有这样的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black">
    <LinearLayout
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:layout_alignParentTop="true"
        android:orientation="horizontal"
        android:gravity="center"
        android:background="@drawable/background_gray">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:paddingTop="15dp"
            android:paddingBottom="15dp"
            android:paddingLeft="3dp" />
    </LinearLayout>
    <RelativeLayout
        android:id="@+id/container_chat_box"
        android:background="@drawable/conversation_background_gray"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="50dp">
        <EditText
            android:id="@+id/chat_box"
            style="@style/ConversationChatBox" />
    </RelativeLayout>
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bar"
        android:background="@android:color/white"
        android:stackFromBottom="true"
        android:transcriptMode="normal"
        android:layout_above="@id/chat_box"
        android:paddingBottom="15dp"
        android:clipToPadding="false"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:listSelector="@android:color/transparent" />
</RelativeLayout>
当我单击编辑文本时,我希望栏保持在屏幕顶部的位置,但列表视图被向上推,因此看起来像:

----------
[   bar   ]
[list view]
[list view]
[list view]
[list view]
[edit text]
------------
[   bar   ]
[list view]
[list view]
[edit text]
[keyboard ]
我从酒吧里得到的东西被推了起来,然后消失了:

------------
[list view]
[list view]
[list view]
[edit text]
[keyboard ]
我的AndroidManifest上有这个:

android:WindowsOfInputMode=adjustPan

我尝试了不同的值组合来设置android:windowSoftInputMode,但我要么让键盘覆盖编辑文本,要么让整个屏幕向上推


在向上推listview时,有没有办法将该条保持在原位?提前谢谢。

我能够解决这个问题,尽管到目前为止只在几部手机上进行了测试

这就是解决方案:

1将软输入模式更改为android:WindowsOfInputMode=adjustResize,并将android:fitsSystemWindows=true添加到布局根视图中

2创建了一个CustomInsetsLayout类,该类扩展了下面的RelativeLayout代码,因此我可以控制屏幕调整大小时布局的变化

3在这一点上,我在布局的底部有一个不想要的黑条。该栏是边距底部,应该隐藏在导航栏下,但全屏标志不适用于adjustResize。因此,我必须向CustomInsertsLayout添加代码,以便在屏幕调整大小时从根视图中删除底部边距

这就是CustomInsetsLayout类与类描述中的引用和注释的相似之处:

package com.playchat.ui.full;

import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.WindowInsets;
import android.widget.RelativeLayout;

/**
 * http://stackoverflow.com/questions/21092888/windowsoftinputmode-adjustresize-not-working-with-translucent-action-navbar
 *
 * @author Kevin
 *         Date Created: 3/7/14
 *
 * https://code.google.com/p/android/issues/detail?id=63777
 *
 * When using a translucent status bar on API 19+, the window will not
 * resize to make room for input methods (i.e.
 * {@link android.view.WindowManager.LayoutParams#SOFT_INPUT_ADJUST_RESIZE} and
 * {@link android.view.WindowManager.LayoutParams#SOFT_INPUT_ADJUST_PAN} are
 * ignored).
 *
 * To work around this; override {@link #fitSystemWindows(android.graphics.Rect)},
 * capture and override the system insets, and then call through to FrameLayout's
 * implementation.
 *
 * For reasons yet unknown, modifying the bottom inset causes this workaround to
 * fail. Modifying the top, left, and right insets works as expected.
 */
public class CustomInsetsLayout extends RelativeLayout {
    private int[] mInsets = new int[4];

    public CustomInsetsLayout(Context context) {
        super(context);
    }

    public CustomInsetsLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomInsetsLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public final int[] getInsets() {
        return mInsets;
    }

    @Override
    protected final boolean fitSystemWindows(Rect insets) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // Intentionally do not modify the bottom inset. For some reason,
            // if the bottom inset is modified, window resizing stops working.
            // TODO: Figure out why.
            mInsets[0] = insets.left;
            mInsets[1] = insets.top;
            mInsets[2] = insets.right;

            insets.left = 0;
            insets.top = 0;
            insets.right = 0;

            if (insets.bottom > 0) {
                // Remove bottom margin from the root view
                RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
                params.bottomMargin = 0;
                setLayoutParams(params);

            }
        }

        return super.fitSystemWindows(insets);
    }

    @Override
    public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            if (insets.getSystemWindowInsetBottom() > 0) {
                // Remove bottom margin from the root view
                RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
                params.bottomMargin = 0;
                setLayoutParams(params);

            }
            mInsets[0] = insets.getSystemWindowInsetLeft();
            mInsets[1] = insets.getSystemWindowInsetTop();
            mInsets[2] = insets.getSystemWindowInsetRight();
            return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0,
                insets.getSystemWindowInsetBottom()));

        } else {
            return insets;
        }
    }
}

尝试为ListView设置android:layout\u height=match\u parent谢谢您的回复。这并没有改变布局。我想知道这个问题是否与在条形线性布局中使用android:layout\u alignParentTop=true有关。但我想不出更正确的方法来保持屏幕顶部的栏。我将软输入模式更改为:android:windowSoftInputMode=adjustResize,并将android:fitsystemwindows=true添加到外部布局中。遵循了来自的一些代码,现在除了底部出现的黑背之外,所有作品都在进行,因为文章中的变通方法只修复了顶部、左侧和右侧的页边距。实际上,来自的CustomInsetsLayout想法是变通方法的灵感来源。现在仍然需要弄清楚如何移除屏幕底部的黑条。