Answer the question
In order to leave comments, you need to log in
Android, ListView and list items of different height?
It needs to be done in a ListView application, in which the elements are of different heights.
The problem is that when I scroll it, the scrollbar becomes different size in different places.
What can be done about it? How do such lists usually do in applications like twitter?
Here are the test application sources:
ListTestActivity.java
public class ListTestActivity extends Activity {
int[] nlines=new int[50];
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Random rnd=new Random();
for(int i=0;i<50;i++)nlines[i]=rnd.nextInt(10)+1;
((ListView)findViewById(R.id.listview)).setAdapter(new TestAdapter());
}
public class TestAdapter extends BaseAdapter{
public int getCount() {
return 50;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView=View.inflate(ListTestActivity.this, R.layout.item, null);
}
String text="";
for(int i=0;i<nlines[position];i++)text+="qwe qwe qwe test ";
((TextView)convertView.findViewById(R.id.item_textview)).setText(text);
return convertView;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/listview"></ListView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dip">
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/item_textview" android:text="TextView" android:textSize="20dip"></TextView>
</LinearLayout>
Answer the question
In order to leave comments, you need to log in
mmm. Two points that immediately caught my eye:
1) In the API, I came across
---> public void setSmoothScrollbarEnabled (boolean enabled)
The descriptions for it say that it should be OFF for lists with changing element heights.
Accordingly, try to set the value to false.
2) Here the person seems to have the same problem. Just in case, I show, suddenly it was not found.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question