Monday, April 18, 2011

[android-developers] Re: How to create ScrollView and LinearLayout Programatically

Mohammed,

I paste a snippet from my own software. I hope it helps. If you spends
half an hour reading the documentation it should be clear actually
because the idea is very simple.

-Ali


LinearLayout m_LinLayout;
ScrollView m_Scroll;
ImageView m_Img;
TextView m_TxtCol;

m_LinLayout = new LinearLayout(this);

/////////////////////////////////////////////////////////////////
// Add an image etc etc
m_Img = new ImageView(this);
m_Img.setImageResource(R.drawable.exclamation_mark);
m_Img.setPadding(5, 5, 0, 0);

m_TxtCol = new TextView(this);
m_TxtCol.setText("Text comes here.");
m_TxtCol.setPadding(15, 5, 0, 0);

// You can create other controls as well.

m_LinLayout.addView( m_Img, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT) );
m_LinLayout.addView( m_TxtCol, new
LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT) );
// If you have other controls, you should add them here.

m_Scroll = new ScrollView(this);
m_Scroll.addView( m_LinLayout, new
LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT) );
addContentView(m_Scroll, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate