I’m working on an Android project and I need to add buttons to a Layout on runtime. So, this is the layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout">
</LinearLayout>
And this is the Activity:
import android.app.Activity;
import android.widget.*;
import android.widget.TableLayout.LayoutParams;
import android.os.Bundle;
public class PluginsActivity extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.plugins);
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
Button butt = new Button(this);
Button butt2 = new Button(this);
butt.setText("lol");
butt2.setText("lol2");
butt.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
butt2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
layout.addView(butt);
layout.addView(butt2);
}
}
Now, the problem is that when i start the activity, the button 1 “covers” the button 2. In fact if I use LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT) both the buttons are shown. Is there a way to add a “new line” on the LinearLayout? The screen should be like this:
|*******Button1**********|
|*******Button2**********|
Thanks.
Make the oritentation vertical of your LinearLayout in the layout file
and