我通過代碼動態創建TableLayout,並希望在列之間設置邊距。我的TableRows包含的唯一類型的內容是TextViews。Android:設置TableRow內容的邊距(意味着:列之間的邊距)
我的意圖是在每個TextView上放置一個簡單的android:layout_marginRight
。但我想通過xml而不是代碼來定義這個。
我的嘗試:
代碼:
txtView.setTextAppearance(context, R.style.TableTextView);
txtView.setText(content);
tableRow.addView(txtView);
的XML
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TableTextView">
<item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_marginRight">5dip</item>
</style>
</resources>
會發生什麼:
的layout_marginRight
集的XML不起作用,但textAppearance
和textStyle
在XML d中設置工作。我假設setTextAppearance-method是爲TextView分配邊距的錯誤方法?如果我可以通過XML(如我上面試過的)代替Java代碼,那將會非常好。
謝謝!
Thx,看起來不錯,但我該如何將它應用到我的動態生成的TextView對象?問題是我需要使用Java而不是XML來創建TextViews,因爲我的表格中TextView的數量不是靜態的,並且可能會不時變化。 – alapeno
你可以誇大它,我不是一個expe but,但修改後的答案與鏈接 –