[英]How to display an image with many buttons by using coordinates; left,top,right and bottom
我想動態地制作不同分區的游泳池。 所有分區都被認為是按鈕。 按鈕的所有位置都有坐標; 左,上,右和下。 如何使用java代碼動態設置所有按鈕,而不會出現布局問題。 池和分區可能看起來像這個分區圖像 。 也許還有另一種解決方法嗎? 帆布?
ScrollView sv = new ScrollView(this);
RelativeLayout ll = new RelativeLayout(this);
sv.addView(ll);
Button button = new Button(this);//Creating Button
button.setPadding(0, 0, 250, 125);
ll.addView(button);//Finally adding view
Button button1 = new Button(this);//Creating Button
button1.setPadding(250, 0, 500, 250);
ll.addView(button1);//Finally adding view
Button button2 = new Button(this);//Creating Button
button2.setPadding(0, 125, 500, 250);
ll.addView(button2);//Finally adding view
Button button3 = new Button(this);//Creating Button
button3.setPadding(0, 250, 500, 500);
ll.addView(button3);//Finally adding view
如果我理解正確你想要在屏幕的每個角落放置一個,如果是這樣你可以使用如下的東西
`RelativeLayout rl =(RelativeLayout)findViewById(R.id.rl); final Button btn =(Button)findViewById(R.id.btn);
LayoutParams lp =(LayoutParams)btn.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
btn.setLayoutParams(LP); `
你想為每個按鈕復制它,然后改變每個按鈕的對齊方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.