【问题标题】:My footer comes up when keyboard appears键盘出现时我的页脚出现
【发布时间】:2017-05-10 15:59:56
【问题描述】:

我用一些按钮做了一个简单的页脚,它显示得很好,但我只有一个问题,当键盘是visible 时它不应该出现。它应该保持向下并且键盘必须覆盖它。

这是我的布局文件-

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView2"
    android:layout_above="@id/footerView">

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

        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Name"
                android:id="@+id/textView40"
                android:layout_weight="2"
                android:paddingLeft="30dp"
                android:textAlignment="gravity"
                android:layout_gravity="center_vertical" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:ems="10"
                android:id="@+id/ETNameSU"
                android:hint="Daksh Agrawal"
                android:layout_weight="1"
                android:layout_marginRight="30dp" />

    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/footerView"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/view_books"
        android:layout_weight="1" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:layout_weight="1"
        android:src="@drawable/my_profile" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView3"
        android:layout_weight="1"
        android:src="@drawable/post_book" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView4"
        android:layout_weight="1"
        android:src="@drawable/chat" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView5"
        android:layout_weight="1"
        android:src="@drawable/top_donors" />
</LinearLayout>

【问题讨论】:

  • 从清单中移除 adjustPan 或 adjustResize。
  • 清单中没有adjustPan
  • 发布您的整个 xml 布局
  • 你为什么要创建不需要的滚动视图。删除它。
  • 您可以在 Activity 中的 onCreate() 或片段中的 onCreateView() 中使用它 getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

标签: android xml android-layout android-softkeyboard


【解决方案1】:

将此添加到您的清单活动中

    android:windowSoftInputMode="hidden"

【讨论】:

    【解决方案2】:

    交叉手指让我们自定义它-(经过测试并且非常适合我!)

    在您的OnCreate 中初始化您的rootView(XML 中的父视图)和您的footerView

    从你的OnCreate调用这个方法——一旦键盘启动footerView可见性改变

     public void testKeyBoardUp(){
            rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    Rect r = new Rect();
                    rootView.getWindowVisibleDisplayFrame(r);
                    int heightDiff = rel.getRootView().getHeight() - (r.bottom - r.top);
    
                    if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                        //ok now we know the keyboard is up...
                        footer.setVisibility(View.INVISIBLE);
    
    
                    }else{
                        //ok now we know the keyboard is down...
                        footer.setVisibility(View.VISIBLE);
    
    
                    }
                }
            });
        }
    

    希望你喜欢

    【讨论】:

      【解决方案3】:

      删除android:layout_above="@id/footerView"

      【讨论】:

      • 他们会在布局需要滚动的时候开始合并.....我自己的经验
      猜你喜欢
      • 1970-01-01
      • 2013-07-19
      • 1970-01-01
      • 2012-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多