简体   繁体   中英

Adding TextView with padding depending on another TextView

As a beginner in Android, I'm trying to display a tree. 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.

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.

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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