2

如何动态设置相对布局背景?我的相对布局在顶部,不能设置id

4

2 回答 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 = new RelativeLayout (this);

RelativeLayout relativeLayout = (RelativeLayout)FindViewById (Resource.Id.relativeLayout);

relativeLayout.SetBackgroundDrawable (Resources.GetDrawable (Resource.Drawable.imageName));

于 2014-01-15T12:24:31.353 回答