how to add dynamic image with horizontal scrollvie

2019-06-26 08:46发布

问题:

I have to develop five to six horizontal scrolling view,in this scrolling image add dynamic using adapter.

Feature:
1) Image can be drag and drop one scroll view to another

2) image can be move one horizontal scrolling to another view

3) image can be selected/unselected

4) with with all version

i am using this library, but sometime scrolling is not that much smooth(chopping)

回答1:

Check this links may be it's useful to you.
1) Insert a view dynamically in a HorizontalScrollView in Android
2) http://android-er.blogspot.in/2012/07/implement-gallery-like.html
3) Horizontal ListView like Google Catalogs



回答2:

Using this code you can add android control programatically to linear layout and just add Horizontal Scrollview to Linear Layout through xml You will get horizontally listview.

//My coding here.
String[] name={"PRASHANT","PRASHANT","PRASHANT","PRASHANT","PRASHANT","PRASHANT","PRASHANT"} ;

myLInearLayoutmain =(LinearLayout) findViewById(R.id.linearLayoutmain);



for(int i =0;i<6;i++)
{
    LinearLayout li=new LinearLayout(getApplicationContext());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    li.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    LinearLayout.LayoutParams paramsnew = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);


    params1.setMargins(30, 20, 30, 0);
    //add textView
    valueTV = new TextView(this);
    valueTV.setText(""+name[i]);
    valueTV.setId(5);
    valueTV.setLayoutParams(paramsnew);
    valueTV.setGravity(Gravity.CENTER);

    // adding Button to linear
    valueB = new Button(this);
    valueB.setText(""+name[i]);
    valueB.setId(i);
    valueB.setLayoutParams(params);
    valueB.setOnClickListener(this);
    valueB.setGravity(Gravity.CENTER);

    // adding Imageto linear
    img = new ImageView(this);
    img.setImageResource(R.drawable.ic_launcher);
    img.setLayoutParams(paramsnew);


    //add the textView and the Button to LinearLayout
    li.addView(valueTV);
    li.addView(valueB);
    li.addView(img);

    li.setLayoutParams(params1);
    myLInearLayoutmain.addView(li);
}