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

  • Home
  • SEARCH
  • 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 4171968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:30:24+00:00 2026-05-21T00:30:24+00:00

I am new to Android development and am currently enjoying it a lot. I

  • 0

I am new to Android development and am currently enjoying it a lot.

I have been building a UI by using the XML file and found it quite easy to build a static UI.

Now, I need to build a UI where one of the TextView positions changes during runtime.

Can this be done using XML only?

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    >
<TextView
        android:layout_height="wrap_content"
        android:text="0%"
        android:layout_width="wrap_content"
        android:id="@+id/percent"
        android:textSize="15sp"
        android:layout_x="41dip"
        android:layout_y="295dip">
    </TextView>

</AbsoluteLayout>

Now I can position the TextView anywhere by changing the value of layout_x and layout_y. But how to do this at runtime?

I have tried this:

TextView text;

text=(TextView)findViewById(R.id.percent);

Doing text.setText("This can be done"); would easily change the text during run time, but how can I change the postion from code?

  • 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-21T00:30:24+00:00Added an answer on May 21, 2026 at 12:30 am

    If trying out this by using absolute layout, take a look at the following code.

    main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >
    <TextView
        android:text="@string/hello"
        android:layout_height="wrap_content"
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_alignParentRight="true">
    </TextView>
    
    <EditText
        android:hint="xcor"
        android:layout_height="wrap_content"
        android:id="@+id/xcor"
        android:background="@drawable/select"
        android:layout_x="165dip"
        android:layout_width="wrap_content"
        android:layout_y="64dip">
    </EditText>
    <EditText
        android:hint="ycor"
        android:layout_height="wrap_content"
        android:id="@+id/ycor"
        android:layout_x="168dip"
        android:layout_width="wrap_content"
        android:layout_y="168dip">
    </EditText>
        <Button
            android:layout_height="wrap_content"
            android:id="@+id/button"
            android:text="Set Position"
            android:layout_x="218dip"
            android:layout_width="wrap_content"
            android:layout_y="278dip"
            android:background="@drawable/select"
            >
        </Button>
    </AbsoluteLayout>
    

    CustomPosition.java

    public class CustomPosition extends Activity {
        /** Called when the activity is first created. */
    
        LayoutParams params = new LayoutParams(MarginLayoutParams.WRAP_CONTENT, MarginLayoutParams.WRAP_CONTENT, 150, 50);
    
        TextView text;
        EditText xcor;
        EditText ycor;
        Button button;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            text=(TextView)findViewById(R.id.textView1);
            xcor=(EditText)findViewById(R.id.xcor);
            ycor=(EditText)findViewById(R.id.ycor);
            button=(Button)findViewById(R.id.button);
    
            button.setOnClickListener(new View.OnClickListener()
            {
                public void onClick(View v)
                {
                    params.x=Integer.parseInt(xcor.getText().toString());
                    params.y=Integer.parseInt(ycor.getText().toString());
                    text.setLayoutParams(params);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm new to android development and working on a game. I currently have
I'm new to both android and game development and have been trying to create
I am new to Android development and have been following the tutorials available on
I am absolutely new to the Android platform and have been building an application
I am new on android development, and i was currently creating an application using
I am new to Android development. I have both Windows 7 and Mac OS
I am somewhat new to android development and development in general. I have a
I'm quite new to Android development. My understanding is that you can create several
I am new to android development. I have created a popup window which is
I am very new to Android development and Java. Have read around but I'm

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.