简体   繁体   中英

Android ListView scrollable with TextView

I have TextView on the top and ListView on the bottom.

I want when I'm scrolling list TextView also scrolling up and down. Normally scrolling only list fragment but i want to scroll all parent fragment.

How to fix it?

<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout
    android:layout_above="@+id/frame_add"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">        
    <LinearLayout
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:textSize="10sp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:text="text"/>
        <TextView
            android:gravity="center"
            android:textSize="10sp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="text"/>
        <TextView
            android:gravity="center"
            android:textSize="10sp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="text"/>
        </LinearLayout>
        <ListView
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:id="@+id/listFak"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        </ListView>
   </LinearLayout>
<FrameLayout
    android:id="@+id/frame_add"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Add"/>
</FrameLayout>
</RelativeLayout>

Thank you I got solution: SimpleAdapter adapter = new SimpleAdapter(this,maps,R.layout.list_item,from,to); View v = View.inflate(this,R.layout.list_item,null); list.addHeaderView(v); list.setAdapter(adapter);

ok this is an example of having a footer for a listview and you can follow this and create and header as well. First a layout xml for footer

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="7dip"
android:paddingTop="7dip" >

<TextView
    android:id="@+id/footer_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="5dip"
    android:text="loadmore"
    android:textSize="14dip"
    android:textStyle="bold" />

   </LinearLayout>

Now in your activity you have to inflate this footer

     View footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_content, null, false);

attach it to your listview like this

             keywordsListView = (ListView) findViewById(R.id.keyword_listview);
     keywordsListView.addFooterView(loadingFooterView);

If you want to access text views or anyother views in your footer you can do

      footerView.findVIewById(R.id.yourid)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM