我想在 TableRow
的左侧动态添加一个 xml 元素。
这是我的 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 View 添加到表行的左侧。我该怎么做?
编辑: 我尝试将它作为 DrawableWithIntrinsicBounds 添加到表格行的左侧。但它看起来像这样: .形状之间有间隙
最佳答案
您可以使用上面发布的代码创建一个名为:timeline.xml
的 xml 文件。
然后你有一个表格布局,但你也有一个你放在表格中的每个项目的布局。它的名称可能类似于:table_item.xml
然后您可以将 timeline.xml
包含到其中并确保它在您的左侧:
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/timeline.xml" />
关于android - 动态添加 XML 布局到 TableRow Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29696056/