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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:06:43+00:00 2026-05-21T23:06:43+00:00

In my app, I have one (and only one) UI element which isn’t referenced

  • 0

In my app, I have one (and only one) UI element which isn’t referenced in the XML layout file.

That element is a button, instantiated and returned at run-time by a 3rd party library (i.e. I don’t have control over that).

My problem is that I would like some of the elements (TextViews) in the XML layout file to be placed relative to that button, using RelativeLayout.

Is it possible to “reserve an empty slot” in the XML layout file for that button such that I can do something like the following?

    <TextView android:id="@+id/tv_text_under_button"
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        android:layout_below="@+id/btn_dynamically_created_button"
        android:text="" />

Alternatively, if I were to set the layout at run-time using RelativeLayout.LayoutParams.addRule(), what would be the ID of that dynamically created button, if it has no reference at all in the XML layout file?

For example, in the following call:

layoutParams.addRule(RelativeLayout.BELOW, R.id.btn_dynamically_created_button);

What would I put instead of R.id.btn_dynamically_created_button?

Update: Thanks to the answer below, I created a place holder like this:

    <LinearLayout android:id="@+id/btn_dynamically_created_button"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    </LinearLayout>

The challenge now is: How to associate the returned object from getDynamicallyCreatedButton() (returned object is subclass of LinearLayout, not Button), with R.id.btn_dynamically_created_button?

EDIT: This thread seem to address a similar issue, but I am not sure that I understand the solution offered.

  • 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-21T23:06:43+00:00Added an answer on May 21, 2026 at 11:06 pm

    I’d suggest:

    1. Put a LinearLayout with width/height set to wrap-content, horizontal orientation and zero padding as the placeholder.
    2. Orient all the other things to that LinearLayout.
    3. When its time to put the button, simply stick it into the LinearLayout.

    See if that works for you.

    EDIT: attempt at a short example:

    The layout (suitably shortened): you can place other components relative to the LinearLayout with id LinearLayout01.

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_marginTop="2sp" android:layout_marginBottom="2sp" android:layout_height="wrap_content">
            <LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:gravity="right" style="@style/SimpleButtonBar" android:layout_below="@+id/rootlayout" android:layout_alignParentBottom="true">
            </LinearLayout>
            <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_above="@+id/LinearLayout01" android:fillViewport="true">
                    <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/detaillayout">
            </RelativeLayout>
        </ScrollView>
    </RelativeLayout>
    

    The code (for example, this would go in onCreate): fetch your button (you need to make sure it has the right Context, but I figure you’re doing that alright), fetch the LinearLayout, create a layout parameters object and stick your button into the LinearLayout.

    Button b = getButton(); // retrieve your button somehow

    LinearLayout l = (LinearLayout)findViewById(R.id.LinearLayout01);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    l.addView(b, lp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one console app that is doing some lengthy syncing to an ftp
I have one hibernate sequence, that generates all sequence-numbers in my app. When I
I'm hearing that is better to have one connection open upon app start up
I am developing native iPhone app. I have one requirement that, there are 5
I have problem with XML schema. I need inside one element elements of three
I have one app, a UIImage* . I'm painting the image twice: Once in
When I have one app.config in my main project I always have to duplicate
I was just wondering if its normal for an app to a have one
I have one web app works perfectly under linux with jetty-6.1.22. However, when I
In my app I have 2 divs, one with a long list of products

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.