2017-05-14 64 views
0

这是我目前的listivew: enter image description here列表视图无法显示的最后一个项目

我的问题是我不能在列表中显示我的最后一个项目。这就像我的手机切断。

下面是XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="1"> 
    <RelativeLayout 
     android:orientation="vertical" 
     android:id="@+id/border" 
     android:layout_width="match_parent" 
     android:layout_height="280dp" 

     android:background="@drawable/dfcomment3" 
     android:layout_weight="0.07"> 


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

      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="40dp" 
       android:text="Add comment" 
       android:id="@+id/button12" 
       android:layout_marginTop="215dp" 
       android:layout_marginLeft="5dp" /> 
      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="40dp" 
       android:text="Update Post" 
       android:id="@+id/button13" 
       android:layout_marginTop="215dp" /> 
      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="40dp" 
       android:text="Close This" 
       android:id="@+id/button14" 
       android:layout_marginTop="215dp" /> 


     </LinearLayout> 

     <TextView 
      android:layout_marginLeft="10dp" 
      android:textSize="35dp" 
      android:id="@+id/textView11" 
      android:gravity="center" 
      android:text="ID" 
      android:textStyle="bold" 
      android:textColor="#994495" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:id="@+id/textView12" 
      android:text="Name" 
      android:textSize="16dp" 
      android:textColor="#994495" 
      android:layout_marginTop="190dp" 
      android:layout_marginLeft="210dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:id="@+id/textView13" 
      android:text="Lastname" 
      android:textStyle="bold" 
      android:textSize="16dp" 
      android:layout_marginLeft="90dp" 
      android:textColor="#994495" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/id" 
      android:layout_toEndOf="@+id/id" 
      android:layout_marginTop="5dp" /> 

     <TextView 
      android:id="@+id/textView14" 
      android:text="title" 
      android:textSize="15dp" 
      android:textColor="#994495" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="260dp" 
      android:layout_below="@+id/name" 
      android:layout_alignStart="@+id/name" 
      android:layout_marginTop="190dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="descr" 
      android:textSize="21dp" 
      android:textColor="#994495" 
      android:id="@+id/textView15" 
      android:layout_marginLeft="110dp" 
      android:layout_marginTop="60dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="dept" 
      android:textStyle="italic" 
      android:textColor="#994495" 
      android:id="@+id/textView16" 
      android:layout_marginLeft="180dp" 
      android:layout_marginTop="30dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="tags" 
      android:textStyle="italic" 
      android:textSize="14dp" 
      android:textColor="#994495" 
      android:id="@+id/textView17" 
      android:layout_marginLeft="120dp" 
      android:layout_marginTop="30dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="status" 
      android:textSize="25dp" 
      android:textStyle="bold" 
      android:textColor="#70CC86" 
      android:id="@+id/textView18" 
      android:layout_marginLeft="290dp" 
      android:layout_marginTop="10dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="date" 
      android:textColor="#994495" 
      android:id="@+id/textView19" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="190dp" /> 
    </RelativeLayout> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:layout_height="match_parent" > 

     <ListView 
      android:id="@+id/listView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

    </LinearLayout> 
</LinearLayout> 

尽可能我想使用ListView坚持,因为我不熟悉的recyclerview。如果有任何方法可以解决这个问题,我会很高兴。 检查图像以查找我的问题的参考。

实际上列表中有4项,我只能查看2项。

+0

您需要添加您的java代码。问题不在于XML。 – Swarnveer

+0

或者你可能想说你在列表视图中获取数据,但由于屏幕上的空间不足而无法显示它? – Swarnveer

+0

@Swarnveer原谅我对我的判决,是的,你是对的。 –

回答

0

将您的xml改为:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="1"> 
    <RelativeLayout 
     android:orientation="vertical" 
     android:id="@+id/border" 
     android:layout_width="match_parent" 
     android:layout_height="280dp" 
     android:layout_weight="0.07"--> Delete this 
     > 
     .... 
    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:layout_weight="1" -> Add this 
     android:layout_height="0dp" > 

     <ListView 
      android:id="@+id/listView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

    </LinearLayout> 
</LinearLayout> 
1

首先,当你使用权重和layout_weight时,你的XML存在问题,那么你不需要给高度或宽度的尺寸。 这必须是你的XML。 另外我检查了你的XML,你的XML属性也存在一些问题。就像你使用“机器人:layout_below =” @ + D/I“”但在你的XML没有“身份证”

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:weightSum="100"> 
<RelativeLayout 
    android:orientation="vertical" 
    android:id="@+id/border" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:background="@drawable/dfcomment3" 
    android:layout_weight="70"> 


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

     <Button 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="40dp" 
      android:text="Add comment" 
      android:id="@+id/button12" 
      android:layout_marginTop="215dp" 
      android:layout_marginLeft="5dp" /> 
     <Button 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="40dp" 
      android:text="Update Post" 
      android:id="@+id/button13" 
      android:layout_marginTop="215dp" /> 
     <Button 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="40dp" 
      android:text="Close This" 
      android:id="@+id/button14" 
      android:layout_marginTop="215dp" /> 


    </LinearLayout> 

    <TextView 
     android:layout_marginLeft="10dp" 
     android:textSize="35dp" 
     android:id="@+id/textView11" 
     android:gravity="center" 
     android:text="ID" 
     android:textStyle="bold" 
     android:textColor="#994495" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:id="@+id/textView12" 
     android:text="Name" 
     android:textSize="16dp" 
     android:textColor="#994495" 
     android:layout_marginTop="190dp" 
     android:layout_marginLeft="210dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:id="@+id/textView13" 
     android:text="Lastname" 
     android:textStyle="bold" 
     android:textSize="16dp" 
     android:layout_marginLeft="90dp" 
     android:textColor="#994495" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/id" 
     android:layout_toEndOf="@+id/id" 
     android:layout_marginTop="5dp" /> 

    <TextView 
     android:id="@+id/textView14" 
     android:text="title" 
     android:textSize="15dp" 
     android:textColor="#994495" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="260dp" 
     android:layout_below="@+id/name" 
     android:layout_alignStart="@+id/name" 
     android:layout_marginTop="190dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="descr" 
     android:textSize="21dp" 
     android:textColor="#994495" 
     android:id="@+id/textView15" 
     android:layout_marginLeft="110dp" 
     android:layout_marginTop="60dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="dept" 
     android:textStyle="italic" 
     android:textColor="#994495" 
     android:id="@+id/textView16" 
     android:layout_marginLeft="180dp" 
     android:layout_marginTop="30dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="tags" 
     android:textStyle="italic" 
     android:textSize="14dp" 
     android:textColor="#994495" 
     android:id="@+id/textView17" 
     android:layout_marginLeft="120dp" 
     android:layout_marginTop="30dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="status" 
     android:textSize="25dp" 
     android:textStyle="bold" 
     android:textColor="#70CC86" 
     android:id="@+id/textView18" 
     android:layout_marginLeft="290dp" 
     android:layout_marginTop="10dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="date" 
     android:textColor="#994495" 
     android:id="@+id/textView19" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="190dp" /> 
</RelativeLayout> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:orientation="horizontal" 
    android:layout_weight="30" 
    android:layout_height="0dp" > 

    <ListView 
     android:id="@+id/listView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 

</LinearLayout> 
</LinearLayout> 

添加您的Java代码,如果你没有得到4个值到您的ListView

+0

http://imgur.com/a/Q0hjw这就是发生了什么事。使用你的代码 –

+0

并记住你需要纠正你的属性的ID。检查红色下划线 – Swarnveer

+0

http://imgur.com/a/ZRjEB – Swarnveer

相关问题