動態建立ImageView,建立imageview

來源:互聯網
上載者:User

動態建立ImageView,建立imageview

1.布局檔案

<LinearLayout     android:id="@+id/viewGroup"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:gravity="center_horizontal"     android:orientation="vertical" />

2.代碼

ViewGroup group = (ViewGroup) findViewById(R.id.viewGroup);ImageView[] imageViews = new ImageView[images.length];for (int i = 0; i < imageViews.length; i++) {ImageView imageView = new ImageView(this);imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));imageViews[i] = imageView;imageView.setImageResource(R.drawable.ic_launcher);group.addView(imageView);}
這樣就可以在不知道圖片數量的時候,根據擷取到的數量,動態建立ImageView。


動態建立的ImageView不可以加動畫?

就是animation動畫說具體點吧——想做一個撲克牌的遊戲,想把ImageView類型的對象作為每張撲克牌的一個屬性。於是動態建立ImageView 對象。然後一些動畫效果(比如發牌什麼的)想對每張撲克牌的ImageView實現animation。有人說不行,我還在嘗試中。。。
 
怎給動態建立的ImageView添加個click listener?

setOnTouchListener是不是你這個弄錯了,用setOnClickListener ivArrowfwd.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View arg0, MotionEvent arg1) { System.out.println("sdfsdf" +(ImageView) view.findViewById(id).getTag()); return false; //執行完你的操作後,返回true } });
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.