2017-01-30 41 views
0

enter image description here如何添加落後

我需要建立類似的東西,有8個的ImageView Container,並能夠得到每個然後使用代碼的LinearLayout多的ImageView裏,我已經有了代碼,以圖像在畫廊,但是我卡上,我當前的代碼我有這樣的:

<LinearLayout 
    android:orientation="vertical" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <HorizontalScrollView 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:id="@+id/linearImages" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </LinearLayout> 
    </HorizontalScrollView> 

活動:

linearImages = (LinearLayout)findViewById(R.id.linearImages); 
Test = new ImageView(this); 
galleryIntent(){....... 
Test.setImageBitmap(bitmap); 
linearImages.addView(Test); 

但只有兩個圖像的作品!

+0

maibe在佈局中只有更多圖像沒有空間? –

+0

我該如何工作?起初我增加了8個圖像瀏覽器,但它不是正確的方法 –

+0

如果只有其中2個圖像適合它,你想如何在圖像中放置圖像?你必須自己決定。 –

回答

1

試試這個:

在佈局

for (final GalleryItem item : items) { 
    ImageView iv = new ImageView(context); 
    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT 
              , LayoutParams.WRAP_CONTENT); 

    param.setMargins(0, 0, 10, 0); 
    iv.setLayoutParams(param); 
    iv.setImageBitmap(item); 
    iv.setAdjustViewBounds(true); 
    layout.add(iv); //your gallery layout 
} 
0

變化HorizontalScrollViewScrollView

+0

雖然這可能解決問題,但一個好的答案也應該包含一個解釋。 – BDL

0

嘗試定義LayoutParams

Image.setLayoutParams(newLinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT, 
        LinearLayout.LayoutParams.MATCH_PARENT)); 

然後,添加您的意見。

+0

我認爲這是正確的答案 –

0
LayoutInflater layoutInflater = (LayoutInflater) 
         context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

View view = layoutInflater.inflate(R.layout.control, null); 
yourLinerarLayout.add(view); 

這裏,R.layout.controlxml文件在佈局文件夾中包含鑑於單件鑑於添加任何你想要的時間。現在

 <HorizontalScrollView 
       android:id="@+id/image_scroll" 
       android:layout_width="match_parent" 
       android:layout_height="300dp" > 

       <LinearLayout 
        android:id="@+id/gallery_layout" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:orientation="horizontal" > 

       </LinearLayout> 
    </HorizontalScrollView> 

添加使用:

0

使用TableRow並採取ImageViews陣列。將此ImageViews轉換爲TableView,然後將最後的TableView轉換爲LinearLayout

有些事情是這樣的:

TableRow row = new TableRow(mContext); 
final ImageView[] myTextViews = new ImageView[n]; 

同時,爲了回調每個ImageView使用setTaggetTag功能。