2017-05-14 102 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

相關問題