tags:

views:

239

answers:

2

Actually my code is `LinearLayout ll = new LinearLayout(this);

                ll.setId(i);
                ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
                ll.setPadding(0, 0, 0, 5);
                //ll.setClickable(false);

                TextView tv = new TextView(this);                   
                tv.setWidth(5);
                tv.setId(++i);
                tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

                final TextView name = new TextView(this);
                name.setText(user_chat.get(j).toString()); 

                name.setWidth(60);
                name.setId(++i);
                //name.setClickable(false);   
                name.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

                Log.v("TextView name",""+name.getText());

                TextView msg = new TextView(this);
                msg.setText(user_chat.get(++j).toString());                 
                msg.setWidth(100);
                msg.setId(++i);
                //msg.setClickable(false);        
                msg.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

                TextView time= new TextView(this);
                time.setText(user_chat.get(++j).toString());    
                time.setId(++i);
                //time.setClickable(false);        
                time.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

                ll.addView(tv);
                ll.addView(name);
                ll.addView(msg);
                ll.addView(time);                   
                lay.addView(ll);

In this name,msg,time text fields i am displyed.I want name msg and time in proper order i mean same line.But the width is not adjusted to both android and droid .What can i do?Thanks in advance

+1  A: 

I guess by "adjust to both droid and android" you mean "adjust to large-screen Android devices such as Motorola Droid, and to earlier normal-screen Android devices such as the Hero or G1".

I strongly suggest you read this article about how different screen sizes work in Android, and the notion of Device-Independent Pixels (DIPs):

http://developer.android.com/guide/practices/screens_support.html

In your case I believe the information you seek can be found under section 3. Do not use hard-coded pixel values in your code .. Converting from DIPs to pixels.

Jim Blackler
A: 

Why are you not using the third parameter while setting the layout params? constructor for this goes like this...

public LinearLayout.LayoutParams (int width, int height, float weight);

eg:

ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,1.0f));

You can set the third parameter to 1.0

Vishwanath