2015-11-26 6 views
0

У меня есть пять строк imageView, но этот код загружает только 4 строки? Зачем?Загрузить изображения из файла tableLayout android

Java код

tl = (TableLayout) findViewById(R.id.tableLayout); 
for (int i = 0; i < tl.getChildCount(); i++) { 
    View v = tl.getChildAt(i); 
    if (v instanceof TableRow) { 

     for (int j = 0; j < ((TableRow) v).getChildCount(); j++) { 
      View innerView = ((TableRow) v).getChildAt(j); 
      if (innerView instanceof ImageView) { 
       imageList.add((ImageView) innerView); 
       idList.add(innerView.getId()); 
      } 
     } 
    } 
} 

Layout

<TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentStart="false" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="275dp" 
     android:id="@+id/tableLayout"> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView3" 
       android:layout_column="1" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView2" 
       android:layout_column="2" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView" 
       android:layout_column="3" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView25" 
       android:layout_column="5" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView5" 
       android:layout_column="6" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

     </TableRow> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView13" 
       android:layout_column="1" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView12" 
       android:layout_column="2" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView11" 
       android:layout_column="3" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView10" 
       android:layout_column="5" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView14" 
       android:layout_column="6" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

     </TableRow> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView9" 
       android:layout_column="1" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView8" 
       android:layout_column="2" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView6" 
       android:layout_column="3" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView7" 
       android:layout_column="5" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView4" 
       android:layout_column="6" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

     </TableRow> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView18" 
       android:layout_column="1" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView17" 
       android:layout_column="2" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView16" 
       android:layout_column="3" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView15" 
       android:layout_column="5" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView19" 
       android:layout_column="6" 
       android:nestedScrollingEnabled="false" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

     </TableRow> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:nestedScrollingEnabled="false"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView23" 
       android:layout_column="1" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView22" 
       android:layout_column="2" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView21" 
       android:layout_column="3" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView20" 
       android:layout_column="5" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView24" 
       android:layout_column="6" 
       android:src="@drawable/blog_dp_5058985_7848593_tr_woda" /> 

     </TableRow> 

</TableLayout> 
+0

пожалуйста, напишите XML или код, который создает TableLayout – csenga

+0

http://pastebin.com/3q5iRURi, потому что я не могу добавить код здесь. – Pekus

+0

Я проверил ваш код, он отлично работает, все 25 ImageViews были добавлены в imageList. – csenga

ответ

1

я могу сравнения двух ImageView? например image.get (1) .getdrawable() == image.get (2) .getdrawable()?

Нет, таким образом это просто сравнение того, являются ли они одним и тем же объектом или нет. В этом случае это будет ложным. Но, если вы хотите сравнить изображения изображений, тогда вы должны получить их растровое изображение, а затем использовать метод sameAs.

 //comapre objects returns false 
     Log.i("EQ", (imageList.get(0).getDrawable().equals(imageList.get(1).getDrawable())) + ""); 
     Log.i("EQ", imageList.get(0).getDrawable().toString()); //[email protected] 
     Log.i("EQ", imageList.get(1).getDrawable().toString()); //[email protected] 

     BitmapDrawable bitmapDrawable0 = ((BitmapDrawable) imageList.get(0).getDrawable()); 
     Bitmap bitmap0 = bitmapDrawable0 .getBitmap(); 

     BitmapDrawable bitmapDrawable1 = ((BitmapDrawable) imageList.get(1).getDrawable()); 
     Bitmap bitmap1 = bitmapDrawable1 .getBitmap(); 

     //comapre the image returns true 
     Log.i("EQ2", Boolean.toString(bitmap0.sameAs(bitmap1))); 

Где я называюсь ToString() это показывает, что они не являются тем же объектом, хотя они держат то же изображение, sameAs с указанием.

Примечание: вместо равных() метод, «==» оператор будет делать то же самое, что нет никакой разницы

+0

Ye, thanks dude :) – Pekus

Смежные вопросы