4

我必须开发five to six horizontal滚动view,在这个滚动中image添加动态使用adapter

特点:
1)图像可以拖放一个滚动视图到另一个

2)图像可以移动一个水平滚动到另一个视图

3) 可以选择/取消选择图像

4)与所有版本

我正在使用这个,但有时滚动不是那么流畅(切碎)

4

2 回答 2

0

使用此代码,您可以以编程方式将 android 控件添加到线性布局,只需通过 xml 将水平滚动视图添加到线性布局您将获得水平列表视图。

//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);
}
于 2015-03-29T07:23:28.850 回答