相対的なレイアウトの背景を動的に設定するにはどうすればよいですか?上部の相対レイアウト、IDを設定できません
3371 次
2 に答える
10
IDを持つ相対レイアウトがあるとしますrelativeLayout
。次を使用して背景を設定できます。
RelativeLayout rLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
Resources res = getResources(); //resource handle
Drawable drawable = res.getDrawable(R.drawable.newImage); //new Image that was added to the res folder
rLayout.setBackgroundDrawable(drawable);
于 2012-07-18T16:55:32.350 に答える
0
Xamarin.Android(クロスプラットフォーム)でこれを試してください
RelativeLayout RelativeLayout = new RelativeLayout(this);
または
RelativeLayoutrelativeLayout=(RelativeLayout)FindViewById(Resource.Id.relativeLayout);
RelativeLayout.SetBackgroundDrawable(Resources.GetDrawable(Resource.Drawable.imageName));
于 2014-01-15T12:24:31.353 に答える