Placing buttons below each other programmatically in Android? - android

I would like to place some buttons below each other. I tried it this way:
View previousView =null;
RelativeLayout evaluationSections = findViewById(R.id.evaluation_sections);
for (int i = 0; i < getQuestions().length(); i++) {
Button question = new Button(activity);
RelativeLayout.LayoutParams questionLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
if (previousView != null){
questionLayoutParams.addRule(RelativeLayout.BELOW,previousView.getId());
}
question.setLayoutParams(questionLayoutParams);
question.setId(ViewCompat.generateViewId());
question.setText("Question "+i);
evaluationSections.addView(question);
previousView = question;
for (int j=0;j< getAnswers().length();j++){
Button answer = new Button(activity);
RelativeLayout.LayoutParams answerLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
answer.setText("Answer "+j);
if (previousView != null){
answerLayoutParams.addRule(RelativeLayout.BELOW,previousView.getId());
}
answer.setLayoutParams(answerLayoutParams);
evaluationSections.addView(answer);
previousView = answer;
}
The buttons are placed over each other but should be below each other. Do you have any idea what is the reason why it does not work?

Related

what is wrong in this first item in gridlayout?

In this code i am able to create gridlayout. but the first item is in default view and the rest is like what i want. I try debug and I couldn't see what is wrong. Would you help me to solve this.
question="this is a sentence";
String sLetter;
String question = question.replace(" ", "");
//char[] charAr = question.toCharArray();
final ArrayList<String> letters = new ArrayList<>();
for (int k = 0; k < question.length(); k++) {
sLetter = Character.toString(question.charAt(k));
letters.add(sLetter);
}
Collections.sort(letters);
int i;
for (i = 0; i < letters.size();) {
int count = recursiveMethod(letters,i,1);
if (count>0) {
//region text add
View main_view = new View(context);
main_view.setLayoutParams(new LinearLayout.LayoutParams(100, ViewGroup.LayoutParams.WRAP_CONTENT));
gridLayout.setColumnCount(7);
if (question.length()<=7){
gridLayout.setRowCount(1);
}else if (question.length()<12){
gridLayout.setRowCount(2);
}else {
gridLayout.setRowCount(3);
}
GridLayout.Spec colSpan = GridLayout.spec(GridLayout.UNDEFINED,1);
GridLayout.Spec rowSpan = GridLayout.spec(GridLayout.UNDEFINED, 1);
GridLayout.LayoutParams gridParam = new GridLayout.LayoutParams(
rowSpan, colSpan);
gridParam.setGravity(Gravity.FILL_HORIZONTAL);
gridParam.setMargins(5, 10, 5, 10);
final TextView tv = new TextView(context);
tv.setText(letters.get(i).toUpperCase());
tv.setId(i);
tv.setPadding(15, 15, 15, 15);
tv.setTextColor(getResources().getColor(R.color.colorPrimaryLight));
RelativeLayout.LayoutParams relTv = new RelativeLayout.LayoutParams(80, ViewGroup.LayoutParams.WRAP_CONTENT);
relTv.addRule( RelativeLayout.CENTER_HORIZONTAL);
relTv.addRule( RelativeLayout.CENTER_VERTICAL);
tv.setLinksClickable(true);
tv.setTextSize(0, 60);
//tv.setLayoutParams(relTv);
CardView cardView = new CardView(context);
cardView.setCardBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
cardView.setRadius(10);
cardView.setCardElevation(5);
RelativeLayout relativeLayout = new RelativeLayout(context);
relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
final TextView textCount = new TextView(context);
textCount.setText(Integer.toString(count));
RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
relParam.addRule(RelativeLayout.ALIGN_BOTTOM, i);
relParam.addRule(RelativeLayout.RIGHT_OF, i);
textCount.setTypeface(Typeface.DEFAULT_BOLD);
textCount.setTextColor(getResources().getColor(R.color.colorPrimaryLight));
textCount.setTextSize(0, 30);
textCount.setPadding(0,5,5,0);
//textCount.setLayoutParams(relParam);
relativeLayout.addView(tv,relTv);
relativeLayout.addView(textCount,relParam);
cardView.addView(relativeLayout);
//llLetters.addView(tv, lp);
gridLayout.addView(cardView,gridParam);
cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(context, tv.getText()+ "" + textCount.getText(), Toast.LENGTH_SHORT).show();
}
});
//llLetters.addView(gridLayout);
//endregion
i = i + count;
}
else {
i++;
}
}
The first letter of image is at the top left. I want to show that at the bottom right side of the letter. Would you help me to solve problem? Thanks =)
The problem lies here:
relParam.addRule(RelativeLayout.ALIGN_BOTTOM, i);
relParam.addRule(RelativeLayout.RIGHT_OF, i);
If you pass a zero to addRule, it is interpreted as false. Therefore you say, that ALIGN_BOTTOM should be false in your first letter, when i is zero.
See the documentation:
parameter: subject, int: the ID of another view to use as an anchor, or a boolean value (represented as RelativeLayout.TRUE for true or 0 for false).

I need to set text for Textview

How to Set Text for Textview for Particular Id which are generated dynamically in Linear Layout???
else if(j==4)
{
tvprodpcs_tot = new TextView(this);
tvprodpcs_tot.setInputType(InputType.TYPE_CLASS_NUMBER);
tvprodpcs_tot.setId(+i );
int totid=tvprodpcs_tot.getId();
tvprodpcs_tot.setBackgroundResource(R.drawable.edittext);
tvprodpcs_tot.setHeight(60);
tvprodpcs_tot.setPadding(0, 15,0, 15);
tvprodpcs_tot.setTextColor(Color.parseColor("#0000E6"));
tvprodpcs_tot.setBackgroundColor(Color.parseColor("#A2FF74"));
// tvprodpcs_tot.setVisibility(View.INVISIBLE);
// tvprodpcs_tot.setText("a");
tvprodpcs_tot.setLayoutParams(new LinearLayout.LayoutParams(0,90, 20));
tvprodpcs_tot.setGravity(Gravity.RIGHT);
linearLayout.addView(tvprodpcs_tot);
}
** I need to set text at child layout**
LinearLayout pLayout= (LinearLayout) findViewById(R.id.LinLayStkSub);
if (pLayout == null)
{
return;
}
TotClo=0; TotCloKg=0;TotPcs=0;
int rows=pLayout.getChildCount();
for(int i = id; i < pcount ; i++)
{
if ((pLayout.getChildAt(i) instanceof LinearLayout) )
{
LinearLayout SubLayout = (LinearLayout) pLayout.getChildAt(i);
for(int j = 0; j < SubLayout.getChildCount(); j++)
{ }
Try this,
TextView txtResMemberAge = new TextView(RegistrationPatientActivity.this);
txtResMemberAge.setLayoutParams(lparams);
txtResMemberAge.setText("Member Age: " +familyMemberModel.getStrMemberAge());
txtResMemberAge.setTypeface(Typeface.createFromAsset(getAssets(), "Roboto-Regular.ttf"));
txtResMemberAge.setTextSize(14);
txtResMemberAge.setTextColor(Color.parseColor("#9C9C9C"));
linearLayout.addView(txtResMemberAge);
lparams.setMargins(50, 10, 0, 0);

How to fetch text in Textview field through JSON in android?

I am developing android application in which i have 12 Dynamic Frame layout in which Frame layout having Text view,video,and play/pause button over it .I want to fetch text in the Text view field by JSON. But my problem is that when i fetch text in Text view field using JSON text will appear in 12th frame and rest of 11 frame are empty.I don't know how to resolve this .kindly help me .
public class MainActivity extends Activity {
String moviename;
private ProgressDialog pDialog;
VideoView vv;
TextView showingat, movie;
FrameLayout frame;
ArrayList<String> abc;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigationbar);
abc = new ArrayList<>();
new Theaterflow().execute();
//Main Relative layout.
final RelativeLayout rl = (RelativeLayout)findViewById(R.id.MainRelativeLayout);
//Main Scrollview.
final ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
//Main Linearlayout.
final LinearLayout ll = (LinearLayout) findViewById(R.id.LinearLayout1);
//Dynamically creation of Layouts.
FrameLayout.LayoutParams playpausebtn = new FrameLayout.LayoutParams(70, 70);
FrameLayout.LayoutParams sound = new FrameLayout.LayoutParams(55, 35);
FrameLayout.LayoutParams nowshwingat = new FrameLayout.LayoutParams(200, 60);
FrameLayout.LayoutParams movie_name = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 60);
//Defining array for framelayout.
ArrayList fHolder = new ArrayList();
int l = 12;
for (int i = 0; i<=l; i++) {
//Dynamically frameslayout for video
fHolder.add(frame);
frame = new FrameLayout(this);
FrameLayout.LayoutParams frameparams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 350);
frameparams.setMargins(0, 2, 0, 0);
frame.setId(i + 1);
frame.setMinimumHeight(350);
ll.addView(frame);
// Video over frames
vv = new VideoView(this);
vv.setId(i + 1);
vv.setLayoutParams(frameparams);
vv.setMinimumHeight(350);
frame.addView(vv);
//Pause btn over video
Button pausebtn = new Button(this);
pausebtn.setId(i + 1);
pausebtn.setBackgroundResource(R.drawable.pause);
pausebtn.setLayoutParams(playpausebtn);
playpausebtn.gravity = Gravity.CENTER;
frame.addView(pausebtn);
//Play btn over video
Button playbtn = new Button(this);
playbtn.setLayoutParams(playpausebtn);
playbtn.setId(i + 1);
playbtn.setBackgroundResource(R.drawable.playy);
playpausebtn.gravity = Gravity.CENTER;
frame.addView(playbtn);
//Sound btn over video
Button soundbtn = new Button(this);
soundbtn.setLayoutParams(sound);
soundbtn.setId(i + 1);
soundbtn.setBackgroundResource(R.drawable.sound);
sound.setMargins(0, 15, 5, 0);
sound.gravity = Gravity.RIGHT;
frame.addView(soundbtn);
//now showing at over video
showingat = new TextView(this);
showingat.setLayoutParams(nowshwingat);
showingat.setText("Now showing at ");
showingat.setTextSize(15);
showingat.setTextColor(getResources().getColor(R.color.white));
nowshwingat.setMargins(10, 0, 0, 0);
nowshwingat.gravity = Gravity.LEFT | Gravity.BOTTOM;
frame.addView(showingat);
movie = new TextView(MainActivity.this);
movie.setLayoutParams(movie_name);
movie.setId(i+1);
movie.setText(" ");
movie.setTextSize(15);
movie.setTextColor(getResources().getColor(R.color.white));
movie_name.setMargins(10, 10, 0, 0);
movie_name.gravity = Gravity.TOP | Gravity.LEFT;
frame.addView(movie);
}
}
private class Theaterflow extends AsyncTask<String, Void, String> {
// URL to get contents JSON
String url = "http://filfest.in/demo/theater/first-theater-data.php";
JSONArray contents = null;
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Loading Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
#Override
protected String doInBackground(String...urls){
ArrayList arraylist = new ArrayList<HashMap<String, String>>();
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonstr = sh.makeServiceCall(url, null);
if (jsonstr != null) {
try {
JSONObject jObject1 = new JSONObject(jsonstr);
contents = jObject1.optJSONArray("contents");
for (int i = 0; i < contents.length(); i++) {
JSONObject c1 = contents.getJSONObject(i);
moviename = c1.getString("movie_name");
abc.add(moviename);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}
public void onPostExecute(String result) {
if (pDialog.isShowing())
pDialog.dismiss();
for (int i=0;i<abc.size();i++)
{
movie.setText(moviename);
}
}
}
}
Add view Programatically in LinearLayout:
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llParent"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Activity.java:
LinearLayout llParent = (LinearLayout)findViewById(R.id.llParent);
onPostExecute() of AsyncTask:
for (int i=0;i<Your_ArrayList.size(); i++){
TextView txtView = new TextView(this);
txtView.setText(Your_ArrayList.get(i).getMovieName());
llParent.addView(txtView);
}
Edit:
llParent.invalidate();
Hope this will help you.
inside your for loop
movie = new TextView(MainActivity.this);
movie.setTag(i);
insid your onPost() for loop
final int childCount = ll.getChildCount();
for (int y = 0; y < childCount; y++) {
final View child = ll.getChildAt(y);
if (child instanceof FrameLayout) {
int childs = ((FrameLayout) child).getChildCount();
for (int j = 0; j < childs; j++) {
final View childViews = ((ViewGroup) child)
.getChildAt(j);
if (childViews instanceof TextView) {
final Object tagObj = childViews.getTag();
if (tagObj != null && tagObj.equals(i)) {
((TextView) childViews).setText("Movie "
+ i);
}
}
}
}
}

Dynamically adding a button to RelativeLayout not working correctly

My goal is to add a number of buttons (in a 4 column grid) to a RelativeLayout depending on how many "items" are in the database. When I was first learning how to add buttons to a RelativeLayout I just created 6 static buttons and added them the following way (ItemButton is simple class that extends Button):
private void loadItemButtons2(){
itemButtonLayout = (RelativeLayout)findViewById(R.id.itemButtonLayout);
itemButtonLayout.removeAllViews();
ArrayList<Item> items = db.getAllActiveItems();
ItemButton b1, b2, b3, b4, b5, b6;
b1 = new ItemButton(this, items.get(0));
b2 = new ItemButton(this, items.get(1));
b3 = new ItemButton(this, items.get(2));
b4 = new ItemButton(this, items.get(3));
b5 = new ItemButton(this, items.get(4));
b6 = new ItemButton(this, items.get(5));
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams)b1.getLayoutParams();
params1.addRule(RelativeLayout.ALIGN_PARENT_START);
b1.setId(111);
b1.setLayoutParams(params1);
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams)b2.getLayoutParams();
params2.addRule(RelativeLayout.RIGHT_OF, 111);
b2.setId(222);
b2.setLayoutParams(params2);
RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams)b3.getLayoutParams();
params3.addRule(RelativeLayout.RIGHT_OF, 222);
b3.setId(333);
b3.setLayoutParams(params3);
RelativeLayout.LayoutParams params4 = (RelativeLayout.LayoutParams)b4.getLayoutParams();
params4.addRule(RelativeLayout.RIGHT_OF, 333);
b4.setId(444);
b4.setLayoutParams(params4);
RelativeLayout.LayoutParams params5 = (RelativeLayout.LayoutParams)b5.getLayoutParams();
params5.addRule(RelativeLayout.ALIGN_PARENT_START);
params5.addRule(RelativeLayout.BELOW, 111);
b5.setId(555);
b5.setLayoutParams(params5);
RelativeLayout.LayoutParams params6 = (RelativeLayout.LayoutParams)b6.getLayoutParams();
params6.addRule(RelativeLayout.RIGHT_OF, 555);
params6.addRule(RelativeLayout.BELOW, 222);
b6.setId(666);
b6.setLayoutParams(params6);
itemButtonLayout.addView(b1);
itemButtonLayout.addView(b2);
itemButtonLayout.addView(b3);
itemButtonLayout.addView(b4);
itemButtonLayout.addView(b5);
itemButtonLayout.addView(b6);
}
And this gives me a perfect result:
But this is the dynamic solution I came up with, and to me it looks like it is doing the exact same thing but the results come out super wonky:
private void loadItemButtons(){
itemButtonLayout = (RelativeLayout)findViewById(R.id.itemButtonLayout);
itemButtonLayout.removeAllViews();
ArrayList<Item> items = db.getAllActiveItems();
int colCount = 0;
int rowCount = 0;
int i = 0;
while(i < items.size()-1){
ItemButton newItemButton = new ItemButton(this, items.get(i));
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)newItemButton.getLayoutParams();
newItemButton.setId(i);
if(colCount == 0){
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
}else if(colCount == 1){
layoutParams.addRule(RelativeLayout.RIGHT_OF, i-1);
}else if(colCount == 2){
layoutParams.addRule(RelativeLayout.RIGHT_OF, i-1);
}else if(colCount == 3){
layoutParams.addRule(RelativeLayout.RIGHT_OF, i-1);
}
//If we are in any row except the top row, place in reference to the button above it
if(rowCount != 0){
layoutParams.addRule(RelativeLayout.BELOW, i-4);
}
newItemButton.setLayoutParams(layoutParams);
itemButtonLayout.addView(newItemButton);
if(colCount == 3){
colCount = 0;
rowCount += 1;
}else{
colCount += 1;
}
i++;
}
}
Is anyone able to see what I am doing incorrectly or different from the first example??? Any advice is much appreciated!
The reason this is failing for you is because of the IDs you are using. Android uses "reserved" ids for things like the general content area of the app.
Using your code, I was able to add 1000 to each ID and generate the intended result.
Do note my cleanup below:
private void loadItemButtons(){
itemButtonLayout = (RelativeLayout)findViewById(R.id.itemButtonLayout);
itemButtonLayout.removeAllViews();
List<String> items = itemList;
int colCount = 0;
int rowCount = 0;
// # of items per column
int colSpan = 4;
final int itemListSize = itemList.size();
for (int i = 0; i < itemListSize; i++) {
int id = 1000 + i;
ItemButton newItemButton = new ItemButton(this, items.get(i));
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
newItemButton.setId(id);
if(colCount == 0)
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
else
layoutParams.addRule(RelativeLayout.RIGHT_OF, id-1);
//If we are in any row except the top row, place in reference to the button above it
if(rowCount != 0)
layoutParams.addRule(RelativeLayout.BELOW, id-colSpan);
newItemButton.setLayoutParams(layoutParams);
itemButtonLayout.addView(newItemButton);
if(colCount == colSpan - 1)
rowCount += 1;
colCount = (colCount + 1) % colSpan;
}
}
Also, as mentioned in my comment on the original post, you really should use a gridview for this, it's what it was built for.
I can dig a hole with a pitchfork, but I bet a shovel would work better.
I didn't test the code:
private void loadItemButtons(){
itemButtonLayout = (RelativeLayout)findViewById(R.id.itemButtonLayout);
itemButtonLayout.removeAllViews();
ArrayList<Item> items = db.getAllActiveItems();
int colCount = 0;
int rowCount = 0;
int i = 0;
while(i < items.size())
{
ItemButton newItemButton = new ItemButton(this, items.get(i));
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)newItemButton.getLayoutParams();
newItemButton.setId(i);
if(colCount == 0)
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
else
layoutParams.addRule(RelativeLayout.RIGHT_OF, i-1);
//If we are in any row except the top row, place in reference to the button above it
if(rowCount != 0){
layoutParams.addRule(RelativeLayout.BELOW, i-4);
}
itemButtonLayout.addView(newItemButton, i, layoutParams);
if(colCount == 3){
colCount = 0;
rowCount += 1;
}else{
colCount += 1;
}
i++;
}
}

Scroll view with Button, ImageView and viedoView

I try to make scroll view with button, imageview and viedoview.
I create dynamically from my code.
When i put button with video, i can see the both of them. The same with button and imageView.
My problem is when there is videView and imageView. When i have both of them i cant see the VidoView and i seeo only the imageView.
Thank for helping :)
Here is my code:
XML scrollview code:
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/dateMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
</ScrollView>
my java code:
private void addPics() {
extras = getIntent().getExtras();
String s = extras.getString("date");
DataBaseMain data = new DataBaseMain(this);
data.open();
paths = data.getWorkOutPic(s);
data.close();
if(paths == null || paths.length < 1)
return;
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
for(int i = 0; i < paths.length; i++){
Bitmap yourSelectedImage = BitmapFactory.decodeFile(paths[i]);
ImageButton pic = new ImageButton(this);
pic.setImageBitmap(yourSelectedImage);
pic.setAdjustViewBounds(true);
pic.setLayoutParams(lp);
pic.setId(i);
pic.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View arg0) {
selectedPictrue = arg0.getId();
onButtonClickEvent(arg0);
return true;
}
});
linear.addView(pic);
}
}
private void addVideos() {
extras = getIntent().getExtras();
String s = extras.getString("date");
DataBaseMain data = new DataBaseMain(this);
data.open();
videos = data.getWorkOutVideo(s);
data.close();
if(videos == null || videos.length < 1)
return;
LinearLayout linear = (LinearLayout) findViewById(R.id.dateMain);
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
LayoutParams lp2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
for(int i = 0; i < videos.length; i++){
Button b = new Button(this);
b.setLayoutParams(lp2);
b.setText("Delete video");
b.setId(i+50);
linear.addView(b);
b.setOnClickListener(this);
VideoView video = new VideoView(this);
video.setVideoPath(videos[i]);
video.setLayoutParams(lp);
video.setId(i+50);
video.setMediaController(new MediaController(this));
video.bringToFront();
linear.addView(video);
}
}
public void setLogView(String date){
DataBaseMain dataBase = new DataBaseMain(this);
dataBase.open();
all = dataBase.dayLog(date);
dataBase.close();
if (all == null || all[0].length < 1 || all[3][0] == null || all[3][0].equals(""))
return;
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
for (int i = 0; i < all[0].length; i++){
String temporay = "";
for(int j = 0; j < all.length; j++)
{
temporay = temporay + " " + all[j][i];
}
Button mine = new Button(this);
mine.setText(temporay);
mine.setTextColor(getResources().getColor(R.color.black));
mine.setBackgroundColor(color.transparent);
mine.setLayoutParams(lp);
mine.setId(i);
mine.setOnClickListener(this);
linear.addView(mine);
//Toast.makeText(this, ""+i, Toast.LENGTH_SHORT).show();
}
}
It's probably because you have most of your LayoutParams' heights to LayoutParams.MATCH_PARENT. "MATCH_PARENT" means that you want the height of this element to be as big as the parent container. Not sure exactly what you're trying to accomplish layout wise, so I can't recommend a fix other than first trying to set the width to WRAP_CONTENT and taking it from there.

Categories

Resources