2015-10-14 109 views
0

我有这样的XML片段:的ListView砍最后一个项目

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:local="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/footer"> 
    <My.Views.NoResultPanel 
     style="@style/default_no_result_panel" 
     android:id="@+id/noResultPanel" 
     local:textID="@string/no_chat" /> 
    <My.Views.LoadingPanel 
     style="@style/default_loading_panel" 
     android:id="@+id/loadingPanel" 
     local:textID="@string/loading_chat" /> 
    <ListView 
     android:id="@+id/lvChat" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="@null" 
     android:dividerHeight="8dp" 
     android:stackFromBottom="true" 
     android:listSelector="@android:color/transparent" /> 
    <View 
     style="@style/default_divider" 
     android:layout_gravity="bottom" /> 
</FrameLayout> 
    <RelativeLayout 
     android:id="@+id/footer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:padding="8dp"> 
     <ImageView 
      android:id="@+id/imgAttachment" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:padding="8dp" 
      android:layout_centerVertical="true" 
      android:src="@drawable/ic_attachment_grey600_24dp" 
      android:layout_alignParentLeft="true" /> 
     <EditText 
      android:id="@+id/txtMessage" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toLeftOf="@+id/imgVisibility" 
      android:layout_toRightOf="@+id/imgAttachment" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="4dp" 
      android:layout_marginLeft="4dp" 
      android:maxLines="3" 
      android:inputType="textShortMessage" 
      android:hint="@string/write_a_message_here" /> 
     <ImageView 
      android:id="@+id/imgVisibility" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:padding="8dp" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="4dp" 
      android:src="@drawable/ic_eye_grey600_24dp" 
      android:layout_toLeftOf="@+id/imgSend" /> 
     <ImageView 
      android:id="@+id/imgSend" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:padding="8dp" 
      android:layout_centerVertical="true" 
      android:src="@drawable/ic_send_grey600_24dp" 
      android:layout_alignParentRight="true" /> 
    </RelativeLayout> 
</RelativeLayout> 

我需要模拟一个聊天室,所以我采用了android:stackFromBottom

的问题是,当我打开该片断第一次,我发现最后一个项目“切割”。 这是片段的截图。

enter image description here

我做错了什么?

更新代码

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:local="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<RelativeLayout 
    android:id="@+id/footer" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:padding="8dp"> 
    <ImageView 
     android:id="@+id/imgAttachment" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:padding="8dp" 
     android:layout_centerVertical="true" 
     android:src="@drawable/ic_attachment_grey600_24dp" 
     android:layout_alignParentLeft="true" 
     android:background="@drawable/Default_clicked_view_rounded" /> 
    <EditText 
     android:id="@+id/txtMessage" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/imgVisibility" 
     android:layout_toRightOf="@+id/imgAttachment" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="4dp" 
     android:layout_marginLeft="4dp" 
     android:maxLines="3" 
     android:inputType="textShortMessage" 
     android:hint="@string/write_a_message_here" /> 
    <ImageView 
     android:id="@+id/imgVisibility" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:padding="8dp" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="4dp" 
     android:src="@drawable/ic_eye_grey600_24dp" 
     android:layout_toLeftOf="@+id/imgSend" 
     android:background="@drawable/Default_clicked_view_rounded" /> 
    <ImageView 
     android:id="@+id/imgSend" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:padding="8dp" 
     android:layout_centerVertical="true" 
     android:src="@drawable/ic_send_grey600_24dp" 
     android:layout_alignParentRight="true" 
     android:background="@drawable/Default_clicked_view_rounded" /> 
</RelativeLayout> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@id/footer"> 
    <My.Views.NoResultPanel 
     style="@style/default_no_result_panel" 
     android:id="@+id/noResultPanel" 
     local:textID="@string/no_chat" /> 
    <My.Views.LoadingPanel 
     style="@style/default_loading_panel" 
     android:id="@+id/loadingPanel" 
     local:textID="@string/loading_chat" /> 
    <ListView 
     android:id="@+id/lvChat" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="@null" 
     android:dividerHeight="8dp" 
     android:stackFromBottom="true" 
     android:listSelector="@android:color/transparent" /> 
    <View 
     style="@style/default_divider" 
     android:layout_gravity="bottom" /> 
</FrameLayout> 
</RelativeLayout> 
+0

尝试删除'机器人:stackFromBottom = “真”' – Jas

回答

2
<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

你的FrameLayout是匹配父所以它覆盖了整个屏幕第一等是不知道新的布局下方@ + ID /页脚...上它的顶部你有覆盖底部RelativeLayout这是页脚,所以只需要改变你的布局。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:local="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
    //your Footer Layout will always stay in bottom 
<RelativeLayout 
     android:id="@+id/footer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:padding="8dp"> 
     <ImageView 
      android:id="@+id/imgAttachment" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:padding="8dp" 
      android:layout_centerVertical="true" 
      android:src="@drawable/ic_attachment_grey600_24dp" 
      android:layout_alignParentLeft="true" /> 
     <EditText 
      android:id="@+id/txtMessage" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toLeftOf="@+id/imgVisibility" 
      android:layout_toRightOf="@+id/imgAttachment" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="4dp" 
      android:layout_marginLeft="4dp" 
      android:maxLines="3" 
      android:inputType="textShortMessage" 
      android:hint="@string/write_a_message_here" /> 
     <ImageView 
      android:id="@+id/imgVisibility" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:padding="8dp" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="4dp" 
      android:src="@drawable/ic_eye_grey600_24dp" 
      android:layout_toLeftOf="@+id/imgSend" /> 
     <ImageView 
      android:id="@+id/imgSend" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:padding="8dp" 
      android:layout_centerVertical="true" 
      android:src="@drawable/ic_send_grey600_24dp" 
      android:layout_alignParentRight="true" /> 
    </RelativeLayout> 


//your FrameLayout now will adjust above footer 
<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@id/footer">  --------change from +id to id now 
    <My.Views.NoResultPanel 
     style="@style/default_no_result_panel" 
     android:id="@+id/noResultPanel" 
     local:textID="@string/no_chat" /> 
    <My.Views.LoadingPanel 
     style="@style/default_loading_panel" 
     android:id="@+id/loadingPanel" 
     local:textID="@string/loading_chat" /> 
    <ListView 
     android:id="@+id/lvChat" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="@null" 
     android:dividerHeight="8dp" 
     android:stackFromBottom="true" 
     android:listSelector="@android:color/transparent" /> 
    <View 
     style="@style/default_divider" 
     android:layout_gravity="bottom" /> 
</FrameLayout> 

</RelativeLayout> 

更新: 请尝试添加android:transcriptMode="alwaysScroll"属性的ListView

设置列表谈话模式。在记录模式下,列表滚动到底部,以便在添加新项目时可见。通过这种方式,列表将自动滚动到底部。

必须是您引用的以下常数值之一doc

Reference

+0

不幸的是这没有解决问题。我更新了开放的帖子这个更新的代码 – user3471528

+0

你有没有尝试以上的解决方案,并给予Framlayout底部边缘 –

+0

尝试与android:layout_marginBottom =“56dp”但问题仍然 – user3471528

1

与垂直方向的LinearLayout中更换你的父母的RelativeLayout

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:weight="1" 
     android:layout_above="@+id/footer"> 
     .... 
    </FrameLayout> 

    <RelativeLayout 
     android:id="@+id/footer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="8dp"> 
     .... 
    </RelativeLayout> 

</LinearLayout> 

的的FrameLayout将匹配父高度

相关问题