Soru & Cevap

scroolview içerisinde listview oluğunda scrool çalışmıyor? ...

22.04.2014 - 05:32

Hareketli bir sayfa içerisine custom listview eklemek istiyorum. Listview i ekleyince normalde scrool view sayesinde asağı yukarı hareket eden sayfa hareket etmemeye baslıyor. Nerede hata yapıyorum cözüm yöntemini bilen var mı?

[code]

<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fillViewport="true" 
  android:verticalScrollbarPosition="left"
  >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/header"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/searchhh"
             >

            <TextView
                android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Seyahat edin"
                android:textColor="#ffffff" />

            
        </LinearLayout>
       

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/header"
            android:orientation="vertical"
            android:background="#aaa9a9" >

          <ListView
              android:id="@+id/list"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
               >
        
    </ListView>
        </LinearLayout>

        <!-- Content End -->

    </LinearLayout>

</ScrollView>

[/code]

32 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user osmansoykan
osmansoykan
25.04.2014 - 02:48

Listview ve ScrollView her ikiside vertical olarak scroll özelliğine sahip olduğundan layout.xml içerisinde uyarı veriyordur. Fakat bu şekilde kullanmak istiyorsan [code]

public class HelperScrollView {

    public static void getListViewSize(ListView myListView) {

        ListAdapter myListAdapter = myListView.getAdapter();

        if (myListAdapter == null) {

            //do nothing return null

            return;

        }

        //set listAdapter in loop for getting final size

        int totalHeight = 0;

        for (int size = 0; size < myListAdapter.getCount(); size++) {

            View listItem = myListAdapter.getView(size, null, myListView);

            listItem.measure(0, 0);

            totalHeight += listItem.getMeasuredHeight();

        }

      //setting listview item in adapter

        ViewGroup.LayoutParams params = myListView.getLayoutParams();

        params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount()));

        myListView.setLayoutParams(params);

     }  

    }

[/code]

 

şeklinde bir class tanımlayıp, Activity içinde listview e setAdapter yaptıktan sonra HelperScrollView.getListViewSize(listview) çağırarak listview height değerini sabitleyebilir ve en dıştaki scrollview ile scroll yapabilirsin.