2011-09-07 38 views
0

創建創建上rootViewAndroid。對齊根據從代碼

RelativeLayout.LayoutParams buttonParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
    buttonParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
    rootView.addView(getSaveButton(), buttonParams); 

的底部。在XML佈局從代碼並將其置於一個按鈕我有一個列表,高度= WRAP_CONTENT視圖XML的佈局圖。我想在創建按鈕時將列表底部與按鈕頂部對齊。

<ExpandableListView 
     android:id="@+id/episodes_list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="10dp" 
     android:layout_below="@id/show_status_buttons_layout" 
     android:groupIndicator="@drawable/indicator" 
     /> 

我該如何向ListView添加android:layout_above =「@ id/button_save」佈局參數? 謝謝。

回答

0

這應該工作

buttonParams.addRule(RelativeLayout.ABOVE, R.id.button_save); 
+0

沒有。 addRule方法有LayoutParams對象沒有查看 –

+0

啊,這是一個錯字。韋爾,你似乎已經弄清楚了。因此,請設置答案,以便將此問題從未解答的列表中刪除。 – blessenm

0
RelativeLayout.LayoutParams listParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
    listParams.addRule(RelativeLayout.ABOVE, getSaveButton().getId()); 

    episodesList.setLayoutParams(listParams);