繁体   English   中英

如何使用坐标显示带有许多按钮的图像; 左,上,右和下

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM