ListView 实现类似listview + scrollview滚动效果

android 中通过ListView 实现类似listview + scrollview滚动效果:

主要有以下三个步骤:

1.main_listview.xml布局。

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="#F7F7F7"

    android:orientation="vertical">

 

    <ListView      

       android:id="@+id/money_lv"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_marginBottom="5dip"

        android:paddingLeft="5dip"

        android:paddingRight="5dip"

        android:layout_weight="1"

        android:cacheColorHint="@color/transparent"

        android:divider="@null"

        android:fadeScrollbars="true"

        android:scrollbarStyle="outsideOverlay"

        android:scrollbarThumbVertical="@drawable/scroll"/>

 

</ListView>

 

 2. header.xml布局

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

     android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:orientation="vertical"

    >

    <RelativeLayout

        android:id="@+id/my_header_rl"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_marginTop="5dip"

        android:layout_marginBottom="5dip"

    >

           <TextView

                android:id="@+id/my_title_tv"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_centerHorizontal="true"

                android:layout_centerVertical="true"

                android:singleLine="true"

                android:textColor="#432312"

                android:textSize="@dimen/font_title />

           

          <ImageView

                android:id="@+id/my_name_img"

                android:layout_width="wrap_content"

                android:layout_height="match_parent"

                android:layout_alignParentLeft="true"

                android:src="@drawable/my_name_img"/>

          

           <ImageView

                android:id="@+id/my_age_btn"

                android:layout_width="30dip"

                android:layout_height="30dip"

                android:layout_alignParentRight="true"

                android:layout_centerVertical="true"

                android:layout_marginRight="10dip"

                android:padding="5dip"

                android:clickable="true"

                android:visibility="gone"

                android:src="@drawable/my_age_img"/>

        </RelativeLayout>  

 </LinearLayout>

 

3.在代码中按照如下步骤使用就可以。

1) private View headView;

private ListView listView;

private MonkeyInfo mMoneyInfo;

 

2)headView = LayoutInflater.from(this).inflate(R.layout.header, null);

 

 3listView = (ListView)findViewById(R.id.money_lv");

       listView.addHeaderView(headView);

       adapter = new Adapter(MyActivity.thismMoneyInfo);

 

如果想让一个布局同listview一块滚动就可以利用listviewheaderViewfooterView来把布局添加到listview上面。

这样就可以避免了,在外面嵌套一层scrollview而导致的各种问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值