如何在显示器外移动imageView?

时间:2011-12-01 08:22:35

标签: android android-layout

我想要显示一些图像(3或5或7等),使得中间图像位于中央屏幕上,其余图像展开到两侧,如下所示:

    +-------------+
[i] | [i] [i] [i] | [i]
    +-------------+

我写道:

    for(int i=0;i<(numOfPages-1);i++){
        ShadowedImageView image = new ShadowedImageView(this);
        pagesArray[i] = image;
        pagesArray[i].setId((i+1));
    }

    int firstPage = currentPage-((int) (numPagesToLoad/2));
    int lastPage = (currentPage+((int) (numPagesToLoad/2)))+1;

    for(int i=firstPage;i<lastPage;i++){
        pagesArray[i].scale = 11;
        pagesArray[i].download(someUrlToLoadImage);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.leftMargin = -20; // this not work !
        params.addRule(RelativeLayout.RIGHT_OF, (firstPage+i));
        layout.addView(pagesArray[i],params);
    }

我有自定义的ImageView类,我将它们放在RelativeLayout中。

2 个答案:

答案 0 :(得分:1)

尝试使用图库

样本在这里http://www.androidpeople.com/android-gallery-example

希望,它对你有帮助!

答案 1 :(得分:0)

您可以在活动中声明一个relativelayout并使用以下

ImageView image = findViewById(R.id.image);
RelativeLayout.LayoutParams layoutParams = 
    (RelativeLayout.LayoutParams)image.getLayoutParams();
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, 0);
image.setLayoutParams(layoutParams);
相关问题