2016-06-16 9 views
0

私はコードだけでUI要素を作成する方法を見てきましたUI要素をアンドロイドで動的に追加する方法

どうすればいいですか?

RelativeLayout mainLayout = FindViewById<RelativeLayout>(Resource.Id.MainRelativeLayout); 
TextView newText = new TextView(this); 
newText.Text = "HEY THERE NEW TEXT MADE VIA CODE"; 
mainLayout.AddView(newText); 


// Set our view from the "main" layout resource 
SetContentView(Resource.Layout.Main); 
+0

下のタイプを指定する必要がないことが判明します。アンドロイド – mrOak

答えて

0

を使用すると、コンテンツビュー

/ Set our view from the "main" layout resource 
SetContentView(Resource.Layout.Main); 

RelativeLayout mainLayout = FindViewById<RelativeLayout>(Resource.Id.MainRelativeLayout); 
TextView newText = new TextView(this); 
newText.Text = "HEY THERE NEW TEXT MADE VIA CODE"; 
mainLayout.AddView(newText); 

ああを設定した後、あなたのコードを配置する必要があると私はXamarinを使用していますFindViewById < TYPE>

関連する問題