2017-02-23 119 views
0

В моем списке есть только два элемента, и он охватывает половину экрана, но listview все еще показывает прокрутку вокруг него. Я поставил высота wrap_contentУдалить прокрутку в Listview

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> 

Я не хочу прокрутки появляться на ListView, потому что он будет иметь только две вещи, и нет никакой необходимости показать. Я не уверен, что вызывает появление прокрутки.

Любая помощь будет высоко оценена.

Благодарим Вас заранее

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

Попробуйте добавить андроид: layout_height = "match_parent" вместо wrap_content –

+0

Ну я хочу добавить TextView ниже этого ListView. При применении match_parent не будет отображаться текст ниже. Правильно? – Anjum

+0

1. старайтесь не использовать 'fill_parent'. 2. Можете ли вы загрузить xml элементов строки? –

ответ

1

попробовать это:

, чтобы скрыть ScrollBar

<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 Items попробовать:

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; 
    } 
}); 

ИЛИ

yourListView.setScrollContainer(false); 
+0

Ну, он не показывал полосу прокрутки, применяя ваш код. Но он все еще доступен для прокрутки. – Anjum

+0

попробуйте отредактированный код @Anjum – rafsanahmad007

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

попробуйте добавить:

android:scrollbars="none" 
1

пользователь android: scrollbar = "none", как это;

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

Применяя родительский элемент соответствия, он охватывает весь экран. Я хочу добавить текст ниже этого списка – 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>