android - 动态添加 XML 布局到 TableRow Android

标签 android xml tablerow

我想在 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" />

看起来像这样:enter image description here

我想获得时间轴外观。我所有的元素都是动态添加的表格行。我需要将此 xml View 添加到表行的左侧。我该怎么做?

编辑: 我尝试将它作为 DrawableWithIntrinsicBounds 添加到表格行的左侧。但它看起来像这样:enter image description here .形状之间有间隙

最佳答案

您可以使用上面发布的代码创建一个名为: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/

相关文章:

android - PopupWindow + 全屏 => 显示通知栏?

android - OkHttp 切断长响应

Android 如何在用户滚动 scrollview 时使用react

android - 解析 Json 数据时出错

android - 服务从 android OS 5.1.1 自动停止

xml - BPMN 2.0用于信息检索场景的XML现实生活示例?

java - 使用 JAXB 将 XML 解码为现有对象

xml - 使用 XSLT 删除节点后摆脱空行

ios - WatchKit - 如何使用 RowControllerAtIndex 以编程方式更改 UITableViewCell 的背景图像

JavaFX:如何禁用 TableView 中的行?