2011-12-01 28 views
0

我想以這樣的方式來顯示一些圖像(3或5或7等)的中間影像中心屏幕上,其餘分散在兩側,像這樣:如何將imageView移動到外部顯示器上?

+-------------+ 
[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中。

+0

有啥問題? – blessenm

+0

圖片不隱藏,請勿集中設置 – Nips

+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); 
相關問題