我加入一個的LinearLayout視圖中顯示,這種方式:動態添加TextInputLayout不LinearLayout中
LinearLayout ll=(LinearLayout)findViewById(R.id.linearlayout);
TextInputLayout til=new TextInputLayout(MainActivity.this);
til.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
Log.i("TAG","BEFORE: "+ll.getChildCount());
ll.addView(til);
Log.i("TAG","AFTER: "+ll.getChildCount());
這樣,沒有顯示直到對象,但補充說,因爲在第二日誌我看到這個數字增加了一個,我剛剛添加的觀點。
爲什麼我看不見?如何在佈局中顯示新視圖?
謝謝。
我認爲它不會顯示,因爲你的'TextInputLayout'是空的。嘗試在'TextInputLayout'中添加'TextInputEditText'。 – pike
嘗試膨脹它:http://stackoverflow.com/questions/31294230/textinputlayout-not-showing-when-view-added-programmatically – codemirel