Android: create TextView at the bottom of a LinearLayout dynamically -


i created app clicking button create textview inside linearlayout(hosted inside scrollview). when click button textviews displayed starting top example:

first image

http://imgur.com/8fhtyzs (sorry don't have reputation display in post inserted link)

but task create textviews @ bottom of linearlayout , make textviews created scroll new one. (sorry bad english) show example more comprehensible.

second image

http://imgur.com/rlhooah

this code:

public class messaggi2 extends actionbaractivity implements onclicklistener {  linearlayout mlayout; scrollview scroll; button invia;   @override    protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.messaggi2);      mlayout = (linearlayout) findviewbyid(r.id.linearscrolllayout);     scroll = (scrollview) findviewbyid(r.id.scrollview2);     invia = (button) findviewbyid(r.id.invia);     invia.setonclicklistener(this);   }   @override public void onclick(view arg0) {     mlayout.addview(createnewtextview("message")); }  private textview createnewtextview(string text) {     final layoutparams lparams = new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content);     final textview textview = new textview(this);     textview.setlayoutparams(lparams);     textview.settext(text);     textview.setbackgroundresource(r.drawable.balloon_broadcast_incoming_pressed);     return textview; } } 

and layout.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical">      <scrollview         android:id="@+id/scrollview2"         android:layout_width="fill_parent"         android:layout_height="640dp"         android:paddingbottom="@dimen/activity_vertical_margin"         android:paddingleft="@dimen/activity_horizontal_margin"         android:paddingright="@dimen/activity_horizontal_margin"         android:paddingtop="@dimen/activity_vertical_margin" >          <linearlayout             android:id="@+id/linearscrolllayout"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="vertical" >              <textview                 android:id="@+id/messaggio"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:background="@drawable/balloon_broadcast_incoming_pressed"                 android:text="@string/messaggi" />          </linearlayout>     </scrollview>      <linearlayout         android:layout_width="fill_parent"         android:layout_height="match_parent"         android:layout_margintop="70dp"         android:background="@drawable/linear_layout_bg" >          <edittext             android:id="@+id/scrivi"             android:layout_width="440dp"             android:layout_height="wrap_content"             android:layout_weight="1"             android:ems="10"             android:hint="@string/scrivimessaggio" />          <button             android:id="@+id/invia"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_weight="1"             android:background="@drawable/send_btn" />      </linearlayout>  </linearlayout> 

there no such thing linearlayout.bottom, nor can add rule linearlayout.

but news insert linearlayout, 1 decide sequence.. use addview function 3 arguments below

mlayout.addview(view, index, param); 

the index determined order.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -