我想動態地將一個xml元素添加到TableRow
的左側。將XML佈局動態添加到TableRow Android
這是我的xml。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@android:color/black" />
<View
android:id="@+id/view1"
android:layout_width="7dp"
android:layout_height="7dp"
android:layout_centerVertical="true"
android:layout_marginLeft="7dp"
android:background="@drawable/dot" />
</RelativeLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="20dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
它看起來像這樣:
我想獲得一個時間表的樣子。我所有的元素都是動態添加的表格行。我需要將這個XML視圖添加到我的表格行的左側。我怎樣才能做到這一點?
編輯: 我試着將它作爲DrawableWithIntrinsicBounds添加到表格的左側。但它看起來像這樣:。形狀之間存在差距
將「時間線外觀」設置爲表格行的背景會不會更容易(也更高效)?一個簡單的9補丁就可以解決這個問題。或者,可能需要設置表格行來處理時間軸圖形本身的繪製(這可能會更多工作,但如果需要動態更改其顏色,則更靈活)。 –
@MH。我還沒有使用9補丁。任何示例?我將用這個解決方案與背景無關的原因編輯我的問題。請檢查 –
我同意@MH,他說的是真相,真相和唯一的真相 – pskink