【问题标题】:Adding TextView with padding depending on another TextView根据另一个 TextView 添加带有填充的 TextView
【发布时间】:2015-07-10 11:22:34
【问题描述】:

作为 Android 的初学者,我正在尝试展示一棵树。我已经找到了如何以编程方式添加新的 TextViews 但我不知道如何放置它们,我的意思是如何根据父节点设置它们的填充/边距。

非常感谢您的回答,

巴蒂斯特

【问题讨论】:

  • padding/margin 设置为parent,然后将match_parentheightwidth 添加到child
  • 那么我应该使用RelativeLayout而不是LinearLayout吗?

标签: java android binary-tree


【解决方案1】:

亲爱的先使用相对布局作为父级,然后添加文本视图子级。我没有添加相对布局添加相对布局作为父级。

<TextView
    android:id="@+id/txttxt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="node"
    android:textColor="@color/white"
    android:layout_alignParentLeft="true"/>

 <TextView
    android:id="@+id/txttxt12"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_below="@+id/txttxt1"
    android:text="Child"
    android:textColor="@color/white"
    android:layout_alignLeft="@id/txttxt1"/>

这是我为您制作的示例代码。你可以根据你的要求使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 2017-06-22
    • 2017-07-25
    • 1970-01-01
    • 2020-12-18
    相关资源
    最近更新 更多