Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6018701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:18:46+00:00 2026-05-23T03:18:46+00:00

In an Android activity….how do I do the following using just code instead of

  • 0

In an Android activity….how do I do the following using just code instead of XML?

<TextView android:background="#0000ff" android:layout_margin="2dip"/>

I also need text align right…

stuck on it for a while =( if someone could help

thanks

UPDATE

I tried the code below

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( 
            RelativeLayout.LayoutParams.FILL_PARENT,                
            RelativeLayout.LayoutParams.FILL_PARENT);                
            //250);

    lp.setMargins(5,5,5,5);

and i did

row.addView(t1, lp);
row.addView(t2);
row.addView(t3);
row.addView(t4);

I also tried LinearLayout

but t1 for some reason doesn’t show at all anymore….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:18:47+00:00Added an answer on May 23, 2026 at 3:18 am

    here is how to code a textView:

        mTextView = new TextView(this);
        mTextView.setGravity(Gravity.CENTER_VERTICAL);       
        mTextView.setText(R.string.instructions);
        mTextView.setTextColor(0xFF000000);
        mTextView.setPadding(20, 8, 8, 20);
    
        mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);
    
        mScroll = new ScrollView(this);
        mScroll.setScrollbarFadingEnabled(false);
        mTextPane = new RelativeLayout(this);
        mTextPane.setVisibility(View.GONE);
        //mScroll.setVisibility(View.GONE);
    
        mScroll.addView(mTextView);
        mTextPane.addView(mScroll);
    
        Resources res = getResources();
        //Drawable drawable = res.getDrawable(R.drawable.text_pane_feather2);
        Drawable drawable = res.getDrawable(R.drawable.text);
        mTextPane.setBackgroundDrawable(drawable);
    
        //RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( 420, 420 );
        RelativeLayout.LayoutParams lp = 
            new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT,
                    //RelativeLayout.LayoutParams.WRAP_CONTENT);
                    250);
    
        lp.setMargins(0,0,0,30);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL );
        lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    
        layout.addView(mTextPane, lp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an android activity in which I'm using tabs. public class UnitActivity extends
I have an Android Activity with a RelativeLayout and I have implemented the following
I have an Android activity that displays a list of log entries (using a
I have an android activity and a service implemented using aidl. Works like a
I have a very simple Android activity layout like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout
In my Android activity, I create a custom view that extends SurfaceView (using MonoDroid
I am writing the code of an android activity that will display thumbnails of
I am trying to design an android activity layout, I am using Eclipse with
I just got done writing an Android Activity that allows other Activities to call
I have an Android Activity that uses a class that I developed that extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.