SOLVED: Putting Views on top of each other, any way?

Put your problem here if it does not fit any of the other categories.

SOLVED: Putting Views on top of each other, any way?

Postby travisjames » Thu Apr 16, 2009 6:42 am

I have the following code, and in LinearLayout flanel it adds LinearLayouts "layout and layout1" to it but it crashes my program because they are in a ListView.

My real questions is: is there anyway of putting "layout" above "layout 1" in the "flanel" LinearLayout?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         private View makeUserStatusView(Context context, TwitterEntry entry) {
  2.  
  3.              
  4.  
  5.         ImageView iv = new ImageView(context);
  6.  
  7.    Bitmap photo = BitmapCache.getInstance().get(entry.getUser().getProfileImageURL());
  8.  
  9.  
  10.  
  11.    iv.setImageBitmap(photo);
  12.  
  13.    iv.setScaleType(ScaleType.CENTER);
  14.  
  15.    iv.setPadding(0, 4, 4, 0);
  16.  
  17.    iv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  18.  
  19.  
  20.  
  21.    Button click = new Button(context);
  22.  
  23.    click.setBackgroundResource(R.drawable.button);
  24.  
  25.    
  26.  
  27.    TextView name = new TextView(context);
  28.  
  29.         name.setTextSize(10);
  30.  
  31.         name.setTextColor(Color.BLACK);
  32.  
  33.         name.setText(entry.getUser().getName());
  34.  
  35.         name.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  36.  
  37.    
  38.  
  39.    TextView tv = new TextView(context);
  40.  
  41.    tv.setTextSize(10);
  42.  
  43.    tv.setTextColor(Color.BLACK);
  44.  
  45.    tv.setText(entry.getCreatedAt() + "\n" + entry.getText());
  46.  
  47.    tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  48.  
  49.    
  50.  
  51.    LinearLayout layout1 = new LinearLayout(context);
  52.  
  53.    layout1.setOrientation(LinearLayout.HORIZONTAL);
  54.  
  55.    layout1.addView(name);
  56.  
  57.    
  58.  
  59.    LinearLayout layout = new LinearLayout(context);
  60.  
  61.    layout.setOrientation(LinearLayout.HORIZONTAL);
  62.  
  63.    layout.addView(iv);
  64.  
  65.    layout.addView(tv);
  66.  
  67.    
  68.  
  69.    
  70.  
  71.    LinearLayout flanel = new LinearLayout(context);
  72.  
  73.    flanel.setOrientation(LinearLayout.HORIZONTAL);
  74.  
  75.    flanel.setPadding(4, 2, 4, 2);
  76.  
  77.    flanel.addView(layout1);
  78.  
  79.    flanel.addView(layout);
  80.  
  81.    
  82.  
  83.    return flanel;
  84.  
  85.   }
  86.  
  87. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Last edited by travisjames on Thu Apr 16, 2009 7:29 am, edited 1 time in total.
travisjames
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Apr 02, 2009 10:00 pm
Location: Cordova, Tennessee

Top

Postby travisjames » Thu Apr 16, 2009 7:29 am

Nevermind, I solved my problem.
travisjames
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Apr 02, 2009 10:00 pm
Location: Cordova, Tennessee

Postby WarrenFaith » Thu Apr 16, 2009 7:34 am

So can you post the solution? It would help others with the same problem. Thank you!
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby travisjames » Thu Apr 16, 2009 8:05 am

Yes, I can. :]

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. LinearLayout layout1 = new LinearLayout(context);
  2.  
  3.    layout1.setOrientation(LinearLayout.HORIZONTAL);
  4.  
  5.    layout1.addView(name);
  6.  
  7.    
  8.  
  9.    LinearLayout layout = new LinearLayout(context);
  10.  
  11.    layout.setOrientation(LinearLayout.HORIZONTAL);
  12.  
  13.    layout.addView(iv);
  14.  
  15.    layout.addView(tv);
  16.  
  17.    
  18.  
  19.    LinearLayout ontop = new LinearLayout(context);
  20.  
  21.    ontop.setOrientation(LinearLayout.VERTICAL);
  22.  
  23.    ontop.addView(layout1);
  24.  
  25.    ontop.addView(layout);
  26.  
  27.    
  28.  
  29.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


I created another LinearLayout that held the other linear layouts within it.

LinearLayout "ontop" holds horizontal Layouts "layout and layout1" in a vertical layout so that they are on top of each other.
travisjames
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Apr 02, 2009 10:00 pm
Location: Cordova, Tennessee

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests