水平滚动视图中的图像视图?

时间:2012-09-26 22:52:03

标签: android image-gallery horizontalscrollview

我有一个要求,其中我需要有一个加载图像的水平滚动视图。图像没有固定的数字,因为我从服务器获取内容。

不推荐使用Gallery,并且应该使用ViewPager(如android docs中所述)

如何在水平滚动视图中使用无限数量的图像?

2 个答案:

答案 0 :(得分:0)

从Github试用这个项目。这应该满足您的需求。以下是pakerfeldt / android-viewflow

的链接

答案 1 :(得分:0)

 String RecentBooks="http://";

 ArrayList<List<String>> arrrecentbooks= new ArrayList<List<String>> ();
//HorizontalScrollview created programaticallly

HorizontalScrollView scollviewh = new HorizontalScrollView(this);

    View v1=null;

    LinearLayout linear_pmain = new LinearLayout(this);

        linear_pmain.setOrientation(LinearLayout.HORIZONTAL);
        //      linear_pmain.setBackgroundDrawable(getResources().getDrawable(R.drawable.topshelf));bottomthumbnail

// arrrecentbook包含从uri

解析的图像
    int length=arrrecentbooks.size();

 for(int j=0;j<length;j++)
    {
        LayoutInflater vii =     (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        v1=vii.inflate(R.layout.thumbnailrowlayout, null);

        List<String> listitem=arrrecentbooks.get(j);

        String  rimageurl=listitem.get(13); 

        String  rbookprice=listitem.get(10);

  img=(ImageView) v1.findViewById(R.id.imgg);
        TextView txt=(TextView) v1.findViewById(R.id.txtg);
        txt.setText("Rs."+rbookprice+"/-");
        txt.setTypeface(tf,Typeface.NORMAL);    


    img.setTag(new String[]{listitem.get(0),listitem.get(1),listitem.get(2),listitem.get(3),listitem.get(4),listitem.get(5),listitem.get(6),listitem.get(7),listitem.get(8),listitem.get(9),listitem.get(10),listitem.get(11),listitem.get(12),listitem.get(13),listitem.get(14),listitem.get(15),listitem.get(16),listitem.get(17),listitem.get(18),listitem.get(19),listitem.get(20),"recentbooks"});
//image loaded to image view

        {

            imageLoader=new ImageLoader(this);

            imageLoader.DisplayImage(rimageurl, this, img);
        }
        img.setOnClickListener(myIItemClickListener);

        linear_pmain.addView(v1);
    }

    scollviewh.addView(linear_pmain);

    lrecentbooks.addView(scollviewh);
//imgeview on itemclick listener

public OnClickListener myIItemClickListener = new OnClickListener(){

@Override

public void onClick(View v) {


    try{

     RelativeLayout borderlyt=(RelativeLayout)findViewById(R.id.Booklyut);

        borderlyt.setBackgroundResource(R.drawable.bgorange);

        String[] Qtag = (String[]) v.getTag();


        Log.d("myItemClickListener", Qtag + "");

        //v.setBackgroundResource(R.drawable.bgorange);

        Intent itemintent = new   Intent(cxt,NoolDashboardDetailPage.class);


        Bundle b = new Bundle();

        b.putStringArray("iarray", Qtag);

        b.putInt("mflag", 0);

        itemintent.putExtra("android.intent.extra.INTENT", b);

        startActivityForResult(itemintent,2);

    }
    catch (Exception e) {

        // TODO: handle exception
    }
}
};
相关问题