Reputation: 15
Its not giving me any thing.. where i miss something any one help me to sort out it not showing the image as well the textview that i add to the relative layout
RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams
(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
tParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
tParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
LayoutParams rlParams = new LayoutParams(LayoutParams.FILL_PARENT
,LayoutParams.FILL_PARENT);
for (int i=0; i < Math.ceil(MyContants.servicemodellist.size() / 2); i++) {
TextView txt= new TextView(RoomservicsFirstPage.this);
txt.setText(MyContants.servicemodellist.get(i).getOption_text_1());
RelativeLayout rLayout = new RelativeLayout(RoomservicsFirstPage.this);
txt.setLayoutParams(tParams);
rLayout.setLayoutParams(rlParams);
// Adding the TextView to the RelativeLayout as a child
ImageView image = new ImageView(RoomservicsFirstPage.this);
image.setLayoutParams(rlParams);
download(MyContants.servicemodellist.get(i).getImage(),image);
rLayout.addView(image);
rLayout.addView(txt);
rows.addView(rLayout);
}
I solve My problem.. i am not add the layout parameters when add the layout in the tow :)
Upvotes: 0
Views: 166
Reputation: 832
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class MainActivity extends Activity {
TableRow rows;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rows = (TableRow) findViewById(R.id.rows);
RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
tParams.addRule(RelativeLayout.ALIGN_LEFT);
for (int i = 0; i < 10; i++) {
TextView txt = new TextView(this);
txt.setText("" + i);
txt.setId(i + 1);
RelativeLayout rLayout = new RelativeLayout(this);
txt.setLayoutParams(tParams);
// Adding the TextView to the RelativeLayout as a child
ImageView image = new ImageView(this);
image.setImageResource(R.drawable.ic_launcher);
RelativeLayout.LayoutParams iParams = new RelativeLayout.LayoutParams(
20, 20);
iParams.addRule(RelativeLayout.RIGHT_OF, i + 1);
image.setLayoutParams(iParams);
rLayout.addView(image);
rLayout.addView(txt);
rows.addView(rLayout);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Upvotes: 1