2015-07-10 31 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

它幫了我很多,謝謝! –