相关疑难解决方法(0)

水平滚动网格视图

我知道在Android中不可能水平滚动网格视图.但我正在做的是在水平滚动视图中动态添加图像按钮,如下所示:

public class HorizontalScroller extends Activity {
    static int l=0;
     private Rect mTempRect = new Rect();

    static int r1=0;
    static int t=0;
    static int b=0;
    static int x=0;
    static int y=0;
 //Button[]  b1 = new Button[100];
    ImageButton btn[][] = new ImageButton[10][10];

 //ImageButton b1 = new ImageButton(this);
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LinearLayout rl = (LinearLayout)findViewById(R.id.widget92);

        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

        for(int i=0;i<4;i++)
        {
            for(int j=0;j<10;j++)
            {System.out.println("helo");
        /*      l=l+100; …
Run Code Online (Sandbox Code Playgroud)

android scroll gridview

14
推荐指数
4
解决办法
4万
查看次数

android gridview中的水平滚动

我在我的应用程序中有一个网格视图,我需要水平滚动它.我已经尝试将gridview更改为gallery.But然后只有一行可用,但我需要不同的行,如在网格视图中.所以基本上我需要的是一个可以水平滚动的网格视图.有没有有效的方法来做到这一点?提前谢谢.

问候Anu

嗨,感谢您的回复.我尝试使用Gallery并实现了一个在其getView方法中提供多视图的适配器.

我的java文件是:

public class Gridview extends Activity 
{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Gallery g = (Gallery) findViewById(R.id.gallery);
    g.setAdapter(new GridAdapter(this));

    g.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            Toast.makeText(Gridview.this, "" + position, Toast.LENGTH_SHORT).show();
        }
    });
}

public class GridAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;

    private Integer[] mImageIds = {
            R.drawable.icon,
            R.drawable.icon,
            R.drawable.icon,
            R.drawable.icon,
            R.drawable.icon,
            R.drawable.icon,
            R.drawable.icon,
    };

    public GridAdapter(Context c) {
        mContext = c;
        TypedArray a …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-emulator

9
推荐指数
1
解决办法
3万
查看次数