2015-07-10 33 views
1

作为Android的初学者,我试图展示一棵树。我已经发现如何以编程方式添加新的TextViews,但我不知道如何放置它们,我的意思是如何根据父节点设置它们的填充/边距。根据另一个TextView添加带有填充的TextView

非常感谢您的回答,

巴蒂斯特

+0

将'padding/margin'设置为'parent',然后将'height'和'width'的'match_parent'添加到'child' – hrskrs

+0

http://stackoverflow.com/questions/3159758/suggestions-for-building- a-treeview-control-in-android – 2red13

+0

因此,我应该使用RelativeLayout而不是LinearLayout? –

回答

0

亲爱的第一次使用相对布局父,然后添加文本视图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"/> 

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

+0

它帮了我很多,谢谢! –