简体   繁体   English

根据其他TextView添加具有填充的TextView

[英]Adding TextView with padding depending on another TextView

As a beginner in Android, I'm trying to display a tree. 作为Android的初学者,我正在尝试显示一棵树。 I have already found how to add programmatically new TextViews but I don't know how to place them, I mean how to set their padding/margin depending on the father node. 我已经找到了如何以编程方式添加新的TextView,但是我不知道如何放置它们,我的意思是如何根据父节点设置其填充/边距。

Thanks a lot for your answers, 非常感谢你的回答,

Baptiste 巴蒂斯特

Dear first Use relative layout as parent and then add text view child.i did not add relative layout add relative layout as parent. 亲爱的,首先使用相对布局作为父对象,然后添加文本视图child。i没有添加相对布局,而是将相对布局作为父对象。

<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"/>

this is sample code i made for you. 这是我为您制作的示例代码。 you can use according to your requirement. 您可以根据需要使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM