[英]How can I add an additional LinearLayout between an existing one and a button?
在編程世界中,一切皆有可能(許多開發人員告訴我)。
在您的代碼中,您只需要在onClick方法中添加以下代碼:
LinearLayout layout = new LinearLayout(MainActivity.this);
layout.setBackgroundColor(Color.parseColor("#135517"));
設置背景僅僅是其實現能力的一個示例。 我建議您做的一件事是正確放置它,以確保它適合層次結構。
例如:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) viewToLayout.getLayoutParams();
params.addRule(RelativeLayout.BELOW, R.id.below_id);
使用這段代碼,您將創建一個新的params布局,並向該布局中添加一個規則,在該示例中,該規則被編碼為位於另一個元素下方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.