Android Listview show only one item

后端 未结 5 1369
暗喜
暗喜 2020-12-09 01:40

I have a ListView, where i changed appearence of row, but listview have size of one row, instead of fullscreen.

list_item.xml:



        
相关标签:
5条回答
  • 2020-12-09 02:12

    I Found mistake. tab_news was in ScrollView of TabHost. So stupid mistake( Thanks for help.

    Update:ListView must not be underScrollView in xml. If it is,the same problem occurs.

    Update 2 :You may use NestedScrollView

    0 讨论(0)
  • 2020-12-09 02:20

    If you use ListView inside ScrollView, you have this issue. And my solution is following as:

    1. Create a custom listview which is non scrollable

    public class NonScrollListView extends ListView {
    
    public NonScrollListView(Context context) {
        super(context);
    }
    public NonScrollListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
                    Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();    
    }
    

    }

    2. Use above custom class for xml file

      <xx.xx.NonScrollListView
            android:id="@+id/lv_nonscroll_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </xx.xx.NonScrollListView>
    

    It worked well on all OS-version for me. Hope best for you.

    0 讨论(0)
  • 2020-12-09 02:21

    In list_item.xml's parent LinearLayout, you are using android:layout_height="fill_parent" Obviously it is going to expand vertically.

    OR:

    use monitor tool, go to hierarchy viewer, inspect the running Layout in detail. Find the View with problem, check its attributes/properties are correct, move to its parent View and check it, until you find the issue.

    0 讨论(0)
  • 2020-12-09 02:24

    I think Listview is taking only one record from your data. Just check that have you got all the data, which you are keen to show in Listview.

    OR

    Please check your list_item.xml, Replace

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="**wrap_content**"
    android:orientation="vertical" >
    

    instead of,

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="**fill_parent**"
    android:orientation="vertical" >
    
    0 讨论(0)
  • 2020-12-09 02:34

    Changing the height dynamically gives NPE most of the times... the best solution is to create a custom list view that is non scrollable. You'll find a lot of codes for that.

    0 讨论(0)
提交回复
热议问题