Case: Nested listview in ScrollView, avoid: 1. ListView displays only the first item, 2.ScrollView automatically scrolls to the first position of the ListView

Source: Internet
Author: User

1. Layout files
  
 
  1. <LinearLayout
  2. android:focusable="true"
  3. android:focusableInTouchMode="true"
  4. android:layout_width="match_parent"
  5. android:layout_height="wrap_content"
  6. android:orientation="vertical">
  7. <extra.view.MyGridView
  8. android:id="@+id/gridview"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:horizontalSpacing="2dp"
  12. android:listSelector="#ffffff"
  13. android:numColumns="2"
  14. android:padding="2dp"
  15. android:scrollbars="none"
  16. android:verticalSpacing="2dp" />
  17. </LinearLayout>
2. Customizing the ListView
  
 
  1. package com.example.chechengwang.view;
  2. import android.content.Context;
  3. import android.util.AttributeSet;
  4. import android.widget.ListView;
  5. /**
  6. * 余天然 on 2015/7/27 10:19
  7. * 邮箱:[email protected]
  8. * 博客:http://my.oschina.net/u/2345676/blog
  9. * 座右铭:知识来自积累,经验源于总结
  10. */
  11. public class MyListView extends ListView {
  12. public MyListView(Context context) {
  13. super(context);
  14. }
  15. public MyListView(Context context, AttributeSet attrs) {
  16. super(context, attrs);
  17. }
  18. /span>public mylistview ( context Context attributeset Attrs int defstyleattr ) {
  19. super(context, attrs, defStyleAttr);
  20. }
  21. @Override
  22. /span>public void Onmeasure ( int Widthmeasurespec int ) {
  23. int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
  24. MeasureSpec.AT_MOST);
  25. super.onMeasure(widthMeasureSpec, expandSpec);
  26. }
  27. }



From for notes (Wiz)

Case: Nested listview in ScrollView, avoid: 1. ListView displays only the first item, 2.ScrollView automatically scrolls to the first position of the ListView

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.