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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:21:51+00:00 2026-05-28T15:21:51+00:00

i want to position a viewstub inside a viewgroup pogrammatically. i tried using the

  • 0

i want to position a viewstub inside a viewgroup pogrammatically.
i tried using the setLayoutParams() method but its not available for viewstubs.
Please suggest any solution.

below is my code.

setContentView(R.layout.textplay);
bt = (Button) findViewById(R.id.button1);

bt.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                panel = (ViewStub) findViewById(R.id.serachViewStub2);
                panel.inflate(getApplicationContext(), R.layout.half_screen,null);
                panel.setVisibility(View.VISIBLE);      
                panel.setOnInflateListener(new OnInflateListener() {

                    @Override
                    public void onInflate(ViewStub arg0, View arg1) {
                        // TODO Auto-generated method stub

                        parentLayout = (LinearLayout) findViewById(R.id.stubLayout1);
                        parentLayout.setLayoutParams(new LinearLayout.LayoutParams(0, 300));

            }
        });
                    }
        });

halfscreen.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/stubLayout1" android:layout_width="fill_parent"
    android:layout_height="50dp" android:weightSum="100"
    android:padding="2dp" 
    android:orientation="horizontal" android:background="@color/white">
    <EditText android:id="@+id/editText1" android:layout_height="40dp"
        android:layout_width="fill_parent" android:layout_weight="10"
        android:hint="Search Location" android:paddingTop="2dp">
        <requestFocus></requestFocus>
    </EditText>
    <Button android:id="@+id/search_button" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_weight="90"
        android:background="@drawable/custom_search_button">
    </Button>
</LinearLayout>

textplay.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="25dp"
    android:paddingTop="25dp" android:paddingRight="25dp" android:background="@drawable/back2">
    <EditText android:layout_height="wrap_content"
        android:layout_width="match_parent" android:id="@+id/editText1"
        android:hint="Type a Command">
        <requestFocus></requestFocus>
    </EditText>
    <LinearLayout android:layout_height="wrap_content"
        android:layout_width="match_parent" android:id="@+id/linearLayout1"
        android:weightSum="100">
        <Button android:id="@+id/button1" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="90"
            android:text="Try Command"></Button>
        <ToggleButton android:text="ToggleButton" android:id="@+id/toggleButton1"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:paddingBottom="10dp" android:layout_weight="10"></ToggleButton>
    </LinearLayout>
    <TextView android:id="@+id/textView1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Invalid"
        android:gravity="center" android:layout_gravity="center"></TextView>
<ViewStub android:id="@+id/serachViewStub2" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:inflatedId="@+id/search_stub"
            android:layout="@layout/half_screen">
        </ViewStub>

</LinearLayout>  
  • 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-28T15:21:52+00:00Added an answer on May 28, 2026 at 3:21 pm

    After you inflate the ViewStub, you can access the layout which the ViewStub is actually showing. Get a reference to the layout and setLayoutparameters on it.

    ViewStub inflates my_layout.xml which contains a LinearLayout with id as mainContainer.
    Once you inflate the viewstub, get a reference to the mainContainer and apply layout parameters on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not really sure what I need here but I want to position a
i want the draggable object to revert back to its original position when i
I want to position some menu items to the left of Honycomb's ActionBar, but
I'm using qplot to plot a function and I want to position the legend
I want to get the position of a an element in its parent. For
I want to position an element in normal css relative to the element before
I want to position Dojo's Dijit Dialog relative to one of my html element.
Let's say I want to position an element at the coordinates x=20, y=5 within
In Autohotkey, I want to position my Gui window to right bottom of the
I want to get hold of the mouse position in a timeout callback. As

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.