請幫助我嗎?我有相對佈局,在這個佈局中有2個文本視圖,一個圖片框在左邊,一個在右邊,我需要添加這個動態組合,但我仍然有這個錯誤。如何爲動態佈局添加樣式
我的錯誤代碼:
和這裏是我的風格(資源/價值/ style.xml) XML風格
我有別人誰可以幫我?謝謝
請幫助我嗎?我有相對佈局,在這個佈局中有2個文本視圖,一個圖片框在左邊,一個在右邊,我需要添加這個動態組合,但我仍然有這個錯誤。如何爲動態佈局添加樣式
我的錯誤代碼:
和這裏是我的風格(資源/價值/ style.xml) XML風格
我有別人誰可以幫我?謝謝
風格和背景資源都是不同
,所以你必須寫像下面
RelativeLayout someLayout = new RelativeLayout(context, null, R.style.mystyle);
IDE無法在你的代碼。嘗試此找到資源文件夾。
_line.setBackgroundResource(R.style.Folder_Style_LineColor);
請你可以告訴我setBackgroundResource(R.style.Folder_Style_LineColor)有什麼區別;和.SetBackgroundResource(Resource.Style.Folder_Style_LineColor); – Penter
我的代碼:
MainActivity.cs
RelativeLayout _tempLay = new RelativeLayout(this);
_tempLay.SetBackgroundResource(Resource.Style.Folder_Style);
ImageView _line = new ImageView(this);
_line.SetBackgroundResource(Resource.Style.Folder_Style_LineColor);
TextView _title = new TextView(this);
_title.SetBackgroundResource(Resource.Style.Folder_Style_Title);
_title.Text = "My Title";
TextView _des = new TextView(this);
_des.SetBackgroundResource(Resource.Style.Folder_Style_Description);
_des.Text = "Description...";
_tempLay.AddView(_line);
_tempLay.AddView(_title);
_tempLay.AddView(_des);
LinearLayout lal = this.FindViewByIdL<LinearLayout>(Resource.Id.linearLayout1);
lal.AddView(_tempLay);
資源/價值/ style.xm
<style name="Folder_Style" parent="@android:Theme.Holo.Light">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">75dp</item>
<item name="android:background">@color/Gray_75</item>
</style>
<style name="Folder_Style_LineColor" parent="@android:Theme.Holo.Light">
<item name="android:layout_width">15dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:background">@color/Blue_500</item>
</style>
<style name="Folder_Style_Title" parent="@android:Theme.Holo.Light">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">40dp</item>
<item name="android:textSize">25dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textColor">@color/BackGround_Title</item>
<item name="android:layout_marginLeft">25dp</item>
<item name="android:layout_marginRight">55dp</item>
</style>
<style name="Folder_Style_Description" parent="@android:Theme.Holo.Light">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">30dp</item>
<item name="android:textSize">15dp</item>
<item name="android:gravity">top</item>
<item name="android:textColor">@color/Gray_700</item>
<item name="android:layout_marginLeft">25dp</item>
<item name="android:layout_marginRight">55dp</item>
<item name="android:layout_marginTop">40dp</item>
</style>
更新您的代碼塊(文本)代碼,而不是截圖。 –
重複的https://stackoverflow.com/questions/11723881/android-set-view-style-programmatically – Sach
你的代碼對我來說很好,嘗試清理和重建你的項目。 –