开发者

How to position a Button in a RelativeLayout through code?

< RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
        < Button android:text="Previous" 
            android:layout_height="wrap_content" 
            android:id="@+id/MeasurePrev"           
            android:layout_alignParentBottom="true"
            android:layout_width="wrap_content">
        < / Button>
< / RelativeLayout >

Can anyone tell me how can i do this using Java code or in activity class? I do not know how 开发者_Go百科to set android:layout_alignParentBottom="true". I want to implement whole view via java code.


Here is a dynamic equivalent of your code :

    RelativeLayout rl = new RelativeLayout(this);
    LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    rl.setLayoutParams(params);
    Button button = new Button(this);
    button.setText("Previous");
    LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    button.setLayoutParams(params1);
    rl.addView(button);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜