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 6336071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:58:44+00:00 2026-05-24T18:58:44+00:00

Iam using below code in xml file and adding child views programmatically by using

  • 0

Iam using below code in xml file and adding child views programmatically by using textview but i need to go specific position(suppose in every textview iam adding number start from 1 then i want to go 5th position textview from total of 10 textviews) on the view using scrollview.I knew the method to scroll but i dont know how to calculate the x y cooardinates from this layout.Please give guidance.

<ScrollView android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:scrollbars="vertical"
        android:id="@+id/agenda_scroll"
        >
        <LinearLayout android:id="@+id/inner_layout"
            android:orientation="vertical" android:layout_width="fill_parent"
            android:layout_height="fill_parent">

        </LinearLayout>
    </ScrollView>

Suppost my code is like this

ScrollView scview = (ScrollView)findViewById(R.id.Scl);
LinearLayout eventLayout = (LinearLayout) findViewById(R.id.inner_layout);
TextView txtView = new TextView(cx);
txtView.setText("1");
eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("2");
eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("3");
eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("4");
eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("5");

int y = txtview.getTop();
Log.d(TAG,"YAxis"+y);//returning 0


eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("6");
eventLayout.addView(txtview);
.........

scview .scrollTo(0,y);///here positions giving (0,0)
  • 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-24T18:58:44+00:00Added an answer on May 24, 2026 at 6:58 pm

    I know this is kind of old, but here’s something that we’ve seen working. Every view has a ViewTreeObserver that can be used to observe the View and it’s hierarchy. Get the ViewTreeObserver and listen for layout changes as follows. Once the view and it’s hierarchy has been laid out, you can perform your size and position based queries.

    onCreate(){
      //Code
    
      eventLayout.addView(txtview);
      TextView txtView = new TextView(cx);
      txtView.setText("6");
      eventLayout.addView(txtview)
    
      //More code
    
      //Observe for a layout change
      ViewTreeObserver viewTreeObserver = eventLayout.getViewTreeObserver();
      if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            //View and it's hierarchy laid out, perform your operations
            scview .scrollTo(0,y);///here positions giving (0,0)
          }
        });
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using XML::Simple for parsing a XML file. Code is given below with
I am using SWFLoader to load a swf file. The code is below: <?xml
I tried created an XML file using below code. $xml = new SimpleXMLElement('<xml />');
I am parsing xml file by using libxml2.0, the code is below here. I
I am using the code below to read a ~2.5Gb Xml file as fast
C# 2008 SP1 I am using the code below: dt.ReadXml(%AppData%\\DateLinks.xml); However, I am getting
I have an XML file like below , using xpath and xnavigator how can
I have generated a XML file automatically from the below code. if (isset($_POST[song])&& $_POST['song']
I am using the C# code below to get the url to an xml
I am using below code to load a xml: XmlDocument xdoc = new XmlDocument();

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.