AVEbrahimi
AVEbrahimi

Reputation: 19144

Setting TextView to right of vertical LinearLayout in android

I tried to add a TextView to a vertical LinearLayout and align the text view to right of layout:

LinearLayout temprLayout=new LinearLayout(this);
            temprLayout.setOrientation(LinearLayout.VERTICAL);

            theTemprature = new TextView(this);
            theTemprature.setVisibility(View.VISIBLE);
            theTemprature.setTextSize(21);
            theTemprature.setTextColor(0xffffCC33);

            theUVText = new TextView(this);
            theUVText.setVisibility(View.VISIBLE);
            theUVText.setTextSize(21);
            theUVText.setTextColor(0xfff5b800);
            theUVText.setBackgroundColor(0xff423234);
            theUVText.setGravity(Gravity.RIGHT | Gravity.TOP);

            theUVText.setLayoutParams(new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                    Gravity.RIGHT));

            temprLayout.addView(theTemprature, new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                    Gravity.RIGHT));
            temprLayout.addView(theUVText, new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                    Gravity.RIGHT));

But the textview remains aligned to the left of layout

Upvotes: 2

Views: 1503

Answers (1)

Alan Moore
Alan Moore

Reputation: 6575

Try setting up your LinearLayout to MATCH_PARENT width.

Upvotes: 4

Related Questions