Note that there are some explanatory texts on larger screens.

plurals
  1. POposition a viewstub programmatically
    primarykey
    data
    text
    <p>i want to position a viewstub inside a viewgroup pogrammatically.<br> i tried using the setLayoutParams() method but its not available for viewstubs.<br> Please suggest any solution. </p> <p>below is my code. </p> <pre><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)); } }); } }); </code></pre> <p>halfscreen.xml </p> <pre><code>&lt;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"&gt; &lt;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"&gt; &lt;requestFocus&gt;&lt;/requestFocus&gt; &lt;/EditText&gt; &lt;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"&gt; &lt;/Button&gt; &lt;/LinearLayout&gt; </code></pre> <p>textplay.xml </p> <pre><code>&lt;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"&gt; &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/editText1" android:hint="Type a Command"&gt; &lt;requestFocus&gt;&lt;/requestFocus&gt; &lt;/EditText&gt; &lt;LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/linearLayout1" android:weightSum="100"&gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="90" android:text="Try Command"&gt;&lt;/Button&gt; &lt;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"&gt;&lt;/ToggleButton&gt; &lt;/LinearLayout&gt; &lt;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"&gt;&lt;/TextView&gt; &lt;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"&gt; &lt;/ViewStub&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload