水平Listview无法从github工作

时间:2015-12-27 13:17:36

标签: android xml listview github android-listview

我正在使用GitHub库来制作位图的水平滚动视图,但这不起作用(aslo尝试用于textview)。

此库中的基本代码我使用了is this

这是我正在使用的自定义Arrayadapter:

public class CustomArrayAdapterForalbumart extends ArrayAdapter<AlbumArtclass> {
    private LayoutInflater mInflater;
    private Context mContext=null;
private List<AlbumArtclass> data=new Vector<AlbumArtclass>();
    public CustomArrayAdapterForalbumart(Context context, List<AlbumArtclass> totalalbumarts) {
        super(context, R.layout.custom_data_view, totalalbumarts);
        this.mContext=context;
        mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   this.data=totalalbumarts;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View row = convertView;
        Holder holder;

        if(row==null)
        {
            LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
            row = mInflater.inflate(R.layout.custom_data_view, parent,false);
            holder= new Holder();
           holder.abumartforeachclass=(ImageView) row.findViewById(R.id.Albumartforsonginpayeractivity);
           row.setTag(holder);
        }
        else
        {
            holder=(Holder) row.getTag();
        }
        AlbumArtclass mrb =data.get(position);

        holder.abumartforeachclass.setImageBitmap(mrb.getAlbumARt());

        return row;
        }

    /** View holder for the views we need access to */
    private static class Holder {
        public ImageView abumartforeachclass;
    }
}

这是Albumart类:

public class AlbumArtclass {
    private Bitmap Albumartforthis=null;


    public AlbumArtclass(Bitmap backgroundColor) {
        Albumartforthis = backgroundColor;

    }
    public Bitmap getAlbumARt() {
        return Albumartforthis;
    }

}

这是我使用的布局(我的XML的一部分):

<ScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<com.androidhive.musicplayer.HorizontalListView
                android:id="@+id/HSVfoalbumarinplayeractivity"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

               </ScrollView>

custom_data_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<ImageView
    android:id="@+id/Albumartforsonginpayeractivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
</LinearLayout>

我正在解决的问题是列表视图没有显示任何数据。

public  void setupp(){
    adapterforalbumarts=new CustomArrayAdapterForalbumart(context, totalalbumarts);//totalalbumart contatins bitmaps
    HSVforimageGallery.setAdapter(adapterforalbumarts);         
    }

Listview显示黑屏。

1 个答案:

答案 0 :(得分:1)

尝试在滚动视图中使用android:fillViewport =“true”

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true" >

<com.androidhive.musicplayer.HorizontalListView
                android:id="@+id/HSVfoalbumarinplayeractivity"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

</ScrollView>