Reputation: 374
In my program I'm using Universal Image Loader.In my list view row size is taking all the screen I searched but I couldn't find what is causing it so here is my Adapter
public class DynamicListView extends BaseAdapter {
ImageLoader imageLoader;
Context c;
String[] images= {"http://3.bp.blogspot.com/-Gsj-34Iyiio/ULEiyinE28I/AAAAAAAADPg/ISUQwGzSBMs/s1600/twitter.png",
"http://a1.mzstatic.com/us/r30/Purple6/v4/99/ee/8e/99ee8e01-f089-d549-f571-1a3797ec660d/icon_256.png" ,
"http://www.wallsave.com/wallpapers/1920x1080/forces-of-nature/1526282/forces-of-nature-1526282.jpg"};
String baslik="Bslik bla bla bla bla bla";
String icerik="Icerik bla bla bla bla bla";
ArrayList<ListViews> lists = new ArrayList<ListViews>();
DynamicListView(Context c )
{
this.c = c;
imageLoader = ImageLoader.getInstance();
for(int i= 0 ; i < 3 ; i++)
{
lists.add( new ListViews(images[i],baslik,icerik));
}
}
@Override
public int getCount() {
return lists.size();
}
@Override
public Object getItem(int position) {
return lists.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
myViewHolder holder = null;
if(row==null)
{
LayoutInflater inflate = (LayoutInflater) c.getSystemService(c.LAYOUT_INFLATER_SERVICE);//Butun layout u inflate'in icine aldik
row = inflate.inflate(R.layout.dynamic_lists , parent , false ); //gerekli islemler
holder = new myViewHolder(row);
row.setTag(holder);
}
else
{
holder = (myViewHolder) row.getTag();
}
imageLoader.displayImage(lists.get(position).image,holder.image );
holder.baslik.setText(lists.get(position).baslik);
holder.icerik.setText(lists.get(position).icerik);
return row;
}
class myViewHolder
{
private ImageView image;
private TextView baslik;
private TextView icerik;
myViewHolder(View v)
{
this.image = (ImageView) v.findViewById(R.id.ivDynamic);
this.baslik = (TextView) v.findViewById(R.id.tvDynamic1);
this.icerik = (TextView) v.findViewById(R.id.tvDynamic2);
}
}
class ListViews
{
ListViews(String image, String baslik, String icerik)
{
this.baslik = baslik;
this.icerik = icerik;
this.image = image;
}
String image;
String baslik;
String icerik;
}
}
and here is my single row to use in getView method
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background">
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:id="@+id/ivDynamic"
android:background="#FFFFFF"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:text="Baslik bla bla"
android:id="@+id/tvDynamic1"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/ivDynamic"
android:paddingLeft="10dp"
android:layout_alignParentRight="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:text="Icerik bla bla bla"
android:id="@+id/tvDynamic2"
android:layout_alignBottom="@+id/ivDynamic"
android:layout_toRightOf="@+id/ivDynamic"
android:layout_below="@+id/tvDynamic1"
android:paddingLeft="7dp"
android:layout_alignParentRight="true" />
</RelativeLayout>
Any help would be appreciated.
Upvotes: 2
Views: 5309
Reputation: 4231
Set android:layout_height="Wrap_content"
in RelativeLayout.
So do something like this.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="Wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background"> // You need to set proper size `background` image here
Edit :
now got point your android:background="@drawable/background"
may having large size.
so please check background
image then try. it may fill screen because your background
image having size more than screen size..You need to set proper size background
image in drawable.
Upvotes: 6
Reputation: 1023
You have to create your list row height with wrap_content
.
Like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background">
Upvotes: 0
Reputation: 6201
Change your Relative Layout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Thanks
Upvotes: 1
Reputation: 6561
this is due to your definition of the row:
<RelativeLayout
...
android:layout_height="fill_parent"
btw fill_parent
is deprecated you shoud use match_parent
instead.
fill_parent means it should fill all available screen so you probably should repace it with wrap_contents
Upvotes: 1