【问题标题】:ListView items hide behind the EditText. Need whatsapp like chat activityListView 项目隐藏在 EditText 后面。需要whatsapp之类的聊天活动
【发布时间】:2015-03-20 11:33:10
【问题描述】:

我的布局实现有问题。每当我单击编辑文本时,软输入键盘就会出现并隐藏列表视图项,我需要的是,每当弹出软键盘并且列表视图的最后一项可见时,它应该放在编辑文本上方,如果它不可见,列表应该保持原样(与whatsapp中的相同),这是我的布局代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_other" >

<include
    android:id="@+id/actionbar_toolbar"
    layout="@layout/toolbar" />

<ListView
    android:id="@+id/lv_listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/line_separator"
    android:layout_below="@+id/actionbar_toolbar"
    android:clipToPadding="false"
    android:divider="@android:color/transparent"
    android:dividerHeight="12dp"
    android:paddingBottom="12dp"
    android:scrollbars="none"
    android:stackFromBottom="true" >
</ListView>

<View 
    android:id="@+id/line_separator"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_above="@+id/ll_editText"
    android:background="#1F000000"/>

<LinearLayout
    android:id="@+id/ll_editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal"
    android:padding="8dp" >

    <EditText
        android:id="@+id/et_editText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:hint="@string/message_hint"
        android:textCursorDrawable="@drawable/cursor_color"
        android:maxLines="4" />

    <View 
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:background="#1F000000"/>

    <Button
        android:id="@+id/btn_Button_send"
        android:layout_width="48dp"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:text="@string/cherry_send"
        android:textColor="@color/orange"
        android:textSize="24sp"
        android:background="@android:color/transparent" />
</LinearLayout>

<Button
    android:id="@+id/btn_Button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/ll_editText"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="5dp"
    android:layout_marginRight="5dp"
    android:background="#A0000000"
    android:paddingLeft="2dp"
    android:paddingRight="2dp"
    android:text="2 new messages"
    android:textColor="@android:color/white"
    android:textSize="14sp"
    android:visibility="gone" />

</RelativeLayout>

我在我的活动清单中使用了 window:softInputMode 作为adjustResize,因为在某些情况下使用adjustPan 会将editText 隐藏在软键盘后面。 请建议我如何实现这一目标。提前致谢

【问题讨论】:

    标签: android listview android-listview whatsapp


    【解决方案1】:

    找到解决办法了....

    mListView.setTransctiptMode(ListView.TRANSCRIPT_MODE_NORMAL);
    

    成功了 :)

    【讨论】:

      【解决方案2】:

      试试这样的 LinearLayou:

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical" >
      
          <ListView
              android:id="@+id/lv_listView"
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_weight="1"
              android:clipToPadding="false"
              android:divider="@android:color/transparent"
              android:dividerHeight="12dp"
              android:paddingBottom="12dp"
              android:scrollbars="none"
              android:stackFromBottom="true" >
          </ListView>
      
          <View
              android:id="@+id/line_separator"
              android:layout_width="match_parent"
              android:layout_height="1dp"
              android:layout_marginLeft="10dp"
              android:layout_marginRight="10dp"
              android:background="#1F000000" />
      
          <LinearLayout
              android:id="@+id/ll_editText"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:padding="8dp" >
      
              <EditText
                  android:id="@+id/et_editText"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical"
                  android:layout_weight="1"
                  android:hint="text"
                  android:maxLines="4" />
      
              <View
                  android:layout_width="1dp"
                  android:layout_height="match_parent"
                  android:layout_marginLeft="5dp"
                  android:background="#1F000000" />
      
              <Button
                  android:id="@+id/btn_Button_send"
                  android:layout_width="48dp"
                  android:layout_height="match_parent"
                  android:layout_gravity="center_vertical"
                  android:background="@android:color/transparent"
                  android:textSize="24sp" />
          </LinearLayout>
      
          <Button
              android:id="@+id/btn_Button"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginBottom="5dp"
              android:layout_marginRight="5dp"
              android:background="#A0000000"
              android:paddingLeft="2dp"
              android:paddingRight="2dp"
              android:text="2 new messages"
              android:textColor="@android:color/white"
              android:textSize="14sp"
              android:visibility="gone" />
      
      </LinearLayout>
      

      【讨论】:

      • 嘿,感谢您的评论......我已经尝试过使用线性布局但没有用......编辑文本仍然在列表视图之上......我觉得它可能是由于 Button btn_Button 我用来显示出现在编辑文本线性布局上方的新消息......无法找到解决该问题的方法
      猜你喜欢
      • 2017-03-31
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多