2017-02-23 148 views
0

我的列表視圖中只有兩個項目,它覆蓋了屏幕的一半,但listview仍然顯示滾動。我已經設置高度WRAP_CONTENT刪除列表視圖中的滾動

enter image description here

佈局代碼如下:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 
    <ListView 
     android:id="@+id/listLikeWhatsapp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="10.0sp" 
     />  

</LinearLayout> 

我不想滾動出現在列表視圖,因爲它只有兩個項目,沒有必要顯示。我不確定是什麼導致滾動出現。

任何幫助將不勝感激。

請多關照

UPDATE

這是我行項目的xml:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 

    android:background="@drawable/roundedshape" 
    android:alpha="0.7"> 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:contentDescription="desc" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:src="@drawable/ic_insert_emoticon_black_48dp" 

     /> 


    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:layout_toRightOf="@+id/icon" 
     android:paddingBottom="5dp" 
     android:text="Assignments" 
     android:textStyle="bold" 
     android:textSize="18sp" 
     android:textColor="#000"/> 

    <TextView 
     android:id="@+id/last_date" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/title" 
     android:layout_below="@+id/title" 
     android:text="Last Update : 01-01-2017" 
     android:textSize="13sp" 
     android:textColor="#696969"/> 



    <TextView 
     android:id="@+id/unread_count" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/title" 
     android:layout_alignBottom="@+id/title" 
     android:layout_alignParentRight="true" 
     android:text="04" 
     android:textSize="12sp" 
     android:background="@drawable/shape_circular" 
     android:padding="5dp" 
     android:textColor="#FFF" 
     android:textStyle="bold" 
     android:layout_marginRight="5dp" 
     /> 
</RelativeLayout> 
+0

嘗試添加了android:layout_height = 「match_parent」 的地方WRAP_CONTENT的 –

+0

嗯,我想添加這個列表視圖下面的TextView。通過應用match_parent將不會顯示textview below.Correct? – Anjum

+0

1.儘量不要使用'fill_parent'。 2.你可以上傳xml的行項目嗎? –

回答

1

試試這個:

隱藏滾動條

<ListView 
    android:id="@+id/listLikeWhatsapp" 
    android:layout_width="match_parent" 
    android:scrollbars="none"  // add this 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="10.0sp" 
    />  

或代碼:

yourlistView.setVerticalScrollBarEnabled(false); 

要禁用的listview項目滾動嘗試:

listView.setOnTouchListener(new OnTouchListener() { 

    public boolean onTouch(View v, MotionEvent event) { 
     if (event.getAction() == MotionEvent.ACTION_MOVE) { 
      return true; // Action will not be forwarded 
     } 
     return false; 
    } 
}); 

OR

yourListView.setScrollContainer(false); 
+0

它沒有通過應用你的代碼來顯示滾動條。但它仍然能夠滾動。 – Anjum

+0

嘗試編輯的代碼@Anjum – rafsanahmad007

1
<ListView 
... 
android:scrollbars="none" 
... 
/> 
1

嘗試添加:

android:scrollbars="none" 
1

user android:scrollbar =「none」like this;

<ListView 
    android:id="@+id/list_view_meals_list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="none" /> 
+0

通過應用匹配父項,它覆蓋了整個屏幕。我想在該列表下方添加textview – Anjum

1

要隱藏滾動條 做到這一點

android:scrollbars="none" 

要禁用滾動爲此

listView.setOnTouchListener(new View.OnTouchListener() { 

    public boolean onTouch(View v, MotionEvent event) { 
     return (event.getAction() == MotionEvent.ACTION_MOVE); 
    } 
}); 

PS:我想你已經搞砸了你的項目視圖,其中包括圖標,標題和描述。

0

使用此代碼.....

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

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="your text view" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:id="@+id/text_ap"/> 

    <ListView 
     android:id="@+id/listLikeWhatsapp" 
     android:layout_width="match_parent" 
     android:layout_above="@id/text_ap" 
     android:layout_height="match_parent"/>  

</RelativeLayout>