0
我想要插入圖像來做按鈕。但是我想通過代碼插入它,沒有.xml文件。有人有任何想法?Android:通過代碼動態插入immage按鈕
我想要插入圖像來做按鈕。但是我想通過代碼插入它,沒有.xml文件。有人有任何想法?Android:通過代碼動態插入immage按鈕
試試這個:
ImageButton ib = new ImageButton(this);
yourContainer.addView(ib);//here yourContainer is ParentLayout
你的「容器」將是一個佈局,例如LinearLayout中,這反過來又繼承的ViewGroup此方法。在這裏查找文檔:http://developer.android.com/reference/android/view/ViewGroup.html#addView%28android.view.View%29 – bgse
我該如何將圖像添加到圖像按鈕? –