I made a UI in Java see screenshot #1 as you can see it displays fine I tried making a similar UI with a custom view…

I made a UI in Java see screenshot #1 as you can see it displays fine I tried making a similar UI with a custom view see screenshot #3 but I can’t get it to display properly can anyone help me fix it cheers.

]]>

3 Commentsto I made a UI in Java see screenshot #1 as you can see it displays fine I tried making a similar UI with a custom view…

  1. Anonymous says:

    < ![CDATA[

    My code



    LL.bindClass(“android.widget.LinearLayout”)


    LL.bindClass(“android.widget.LinearLayout.LayoutParams”)


    LL.bindClass(“android.view.ViewGroup.LayoutParams”);


    LL.bindClass(“android.view.View”);


    LL.bindClass(“android.view.Gravity”);


    LL.bindClass(“android.widget.Button”);


    LL.bindClass(“android.widget.EditText”);


    LL.bindClass(“android.webkit.WebView”);


    LL.bindClass(“android.webkit.WebSettings”);


    LL.bindClass(“android.webkit.WebViewClient”);



    var ctx = LL.getContext();



    // the main layout



    var main = new LinearLayout(ctx);


    main.setOrientation(LinearLayout.VERTICAL);


    main.setGravity(Gravity.TOP);


    main.setBackgroundColor(Color.parseColor(“#ff333333”));



    // layout params for main



    var mp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);


    // set layout params for main layout


    main.setLayoutParams(mp);



    // button container layout


    var buttoncontainer = new LinearLayout(ctx);


    main.setOrientation(LinearLayout.HORIZONTAL);


    main.setBackgroundColor(Color.parseColor(“#ff5722”));



    // button container params



    var buttoncontainerparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);


    // set layout params for button container layout


    buttoncontainer.setLayoutParams(buttoncontainerparams);


    // add button container to main layout


    main.addView(buttoncontainer);



    // button 1



    var b1 = new Button(ctx);


    var b1p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);


    // set layout params for b1


    b1.setLayoutParams(b1p);


    b1.setText(“Button 1”);


    // add b1 to the button container layout


    buttoncontainer.addView(b1);



    // button 2



    var b2 = new Button(ctx);


    var b2p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);


    // set layout params for b2


    b2.setLayoutParams(b2p);


    b2.setText(“Button 2”);


    // add b2 to the button container layout


    buttoncontainer.addView(b2);



    return main;

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Your layout width params need to be P_CONTENT for both buttons (or at least the first one), otherwise the first one eat all the space and there is no remaining pixel for the second.



    Tip: no need for parseColor , use 0xffff5722 instead (first two f are alpha)

    ]]>

  3. Anonymous says:

    < ![CDATA[

    nice problem solved and thanks for the tip.

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *