How to make two buttons on the same row in eclipse programmatically? - android

LinearLayout table = (LinearLayout)findViewById(R.id.linearlayout);
btnControl = new Button(this);
btnControl.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
btnControl.setPadding(0,40,0,40);//x,y,w,h
btnControl.setBackgroundColor(Color.parseColor("#1C344E"));
btnControl.setTextColor(Color.WHITE);
setMargins(btnControl, 50, 50, 50, 50);
btnLogs = new Button(this);
btnLogs.setLayoutParams(new LayoutParams(380, LayoutParams.WRAP_CONTENT));
btnLogs.setPadding(0,40,0,40);//x,y,w,h
btnLogs.setBackgroundColor(Color.parseColor("#1C344E"));
btnLogs.setTextColor(Color.WHITE);
setMargins(btnLogs, 50, 50, 50, 50);
btnLogs.setId(5);
btnLogs.setOnClickListener(this);
btnTermLogs = new Button(this);
btnTermLogs.setLayoutParams(new LayoutParams(380, LayoutParams.WRAP_CONTENT));
btnTermLogs.setPadding(0,40,0,40);//x,y,w,h
btnTermLogs.setBackgroundColor(Color.parseColor("#CC6675"));
btnTermLogs.setTextColor(Color.WHITE);
setMargins(btnLogs, 50, 50, 50, 50);
btnTermLogs.setId(6);
btnTermLogs.setOnClickListener(this);
btnLogout = new Button(this);
btnLogout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
btnLogout.setPadding(0,40,0,40);//x,y,w,h
btnLogout.setBackgroundColor(Color.parseColor("#CC6675"));
btnLogout.setTextColor(Color.WHITE);
table.addView(btnLogs);
table.addView(btnTermLogs);
I want the two buttons to be aligned together horizontally. However it just align themselves vertically which i dont want.
My buttons look like this:
what i want is to look like this:

Try this below function. It will help
public void addButtons(){
LinearLayout table = (LinearLayout)findViewById(R.id.linearlayout);
LinearLayout linearLayout1 = new LinearLayout(this);
linearLayout1.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams LayoutParamsview = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
Button button1 = new Button(this);
button1.setText("Btn 1");
button1.setLayoutParams(LayoutParamsview);
linearLayout1.addView(button1);
table.addView(linearLayout1);
//
LinearLayout linearLayout2 = new LinearLayout(this);
linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
Button button2 = new Button(this);
button2.setText("Btn 2");
button2.setLayoutParams(LayoutParamsview);
Button button3 = new Button(this);
button3.setText("Btn 3");
button3.setLayoutParams(LayoutParamsview);
linearLayout2.addView(button2);
linearLayout2.addView(button3);
table.addView(linearLayout2);
//
LinearLayout linearLayout3 = new LinearLayout(this);
linearLayout3.setOrientation(LinearLayout.VERTICAL);
Button button4 = new Button(this);
button4.setText("Btn 4");
button4.setLayoutParams(LayoutParamsview);
linearLayout3.addView(button4);
table.addView(linearLayout3);
}

Horizontal linear layout supports left to right widgets approach, When
app developer selects horizontal orientation in linear layout then it
will automatically start adding components and widgets to left to
right side after adding them. So here is the complete step by step
tutorial for Creating horizontal linearlayout programmatically
android.
Write this code
//Creating LinearLayout.
LinearLayout Horizontallinearlayout = new LinearLayout(this);
//Setting up LinearLayout Orientation
Horizontallinearlayout.setOrientation(LinearLayout.HORIZONTAL);
LayoutParams Horizontallinearlayoutlayoutparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
setContentView(Horizontallinearlayout, Horizontallinearlayoutlayoutparams);
LayoutParams LayoutParamsview = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//Creating textview .
Button button1 = new Button(this);
Button button2 = new Button(this);
//Adding text to TextView.
button1.setText("First Button");
button2.setText("Second Button");
button1.setLayoutParams(LayoutParamsview);
button2.setLayoutParams(LayoutParamsview);
//Adding textview to linear layout using Add View function.
Horizontallinearlayout.addView(button1);
Horizontallinearlayout.addView(button2);
Hope this helps you

You should use setLayoutParams
Add setOrientation(LinearLayout.HORIZONTAL);
Set the layout parameters associated with this view. These supply
parameters to the parent of this view specifying how it should be
arranged. There are many subclasses of ViewGroup.LayoutParams, and
these correspond to the different subclasses of ViewGroup that are
responsible for arranging their children.
Code Structure
LinearLayout table = (LinearLayout)findViewById(R.id.linearlayout);
table.setOrientation(LinearLayout.HORIZONTAL);
Button Btn1 = new Button(Activity.this);
Btn1.setText("Button 1");
LinearLayout.LayoutParams childParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
childParam.weight = 0.5f;
Btn1.setLayoutParams(childParam);
Button Btn2 = new Button(Activity.this);
Btn2.setText("Button 2");
LinearLayout.LayoutParams childParam2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
childParam2.weight = 0.5f;
Btn2.setLayoutParams(childParam2);
table.addView(Btn1);
table.addView(Btn2);
Respected OP

You can create another XML file, that contains a horizontal LinearLayout, then inflate it and insert the two buttons into it, and then add the whole horizontal LinearLayout to the vertical LinearLayout:
Create an XML file e.g. horizontal_layout.xml:
<LinearLayout
android:id="#+id/horizontal_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
// You will insert the buttons programmatically.
</LinearLayout>
In your Activity use this method to inflate the Layout:
LinearLayout verticalLinearLayout = rootView.findViewById(R.id.vertical_linear_layout);
// Add the first vertical Button regularly.
Button firstVerticalButton = new Button(Activity.this);
firstVerticalButton.setText("Vertical");
verticalLinearLayout.addView(firstVerticalButton);
// Inflate the horizontal LinearLayout and add the two horizontal buttons.
LinearLayout horizontalLinearLayout = getLayoutInflater().inflate(R.layout.horizontal_layout,
linearLayout, false);
Button horizontalOne = new Button(Activity.this);
horizontalOne.setText("Horizontal");
LinearLayout.LayoutParams childParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
childParam1.weight = 0.5f;
horizontalOne.setLayoutParams(childParam);
Button horizontalTwo = new Button(Activity.this);
horizontalTwo.setText("Horizontal");
LinearLayout.LayoutParams childParam2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
childParam1.weight = 0.5f;
horizontalTwo.setLayoutParams(childParam2);
horizontalLinearLayout.addView(horizontalOne);
horizontalLinearLayout.addView(horizontalTwo);
// Insert the inflated layout to the main layout.
verticalLinearLayout.addView(horizontalLinearLayout);
// Add the second vertical Button
Button secondVerticalButton = new Button(Activity.this);
secondVerticalButton.setText("Vertical");
verticalLinearLayout.addView(secondVerticalButton);

use table.setOrientation(LinearLayout.HORIZONTAL); .
Hope it Helps.

Related

Adding a dynamic view - Layout gravity problem

I am adding a dynamic layout view which looks like this.
I am appending this view on button click. Here is the code for this view on button click
public void addDynamicView() {
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
LinearLayout lHori = new LinearLayout(this);
lHori.setOrientation(LinearLayout.HORIZONTAL);
//lHori.setWeightSum(3);
lHori.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
LinearLayout lVertical = new LinearLayout(this);
lVertical.setOrientation(LinearLayout.VERTICAL);
//lVertical.setWeightSum(2);
lVertical.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
Button button = new Button(this);
button.setLayoutParams(new LinearLayout.LayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)));
button.setVisibility(View.VISIBLE);
button.setText("button");
TextView txtEmpName = new TextView(this);
txtEmpName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
txtEmpName.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
txtEmpName.setText("txt1");
TextView txtEmpDropTime = new TextView(this);
txtEmpDropTime.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
txtEmpDropTime.setText("txt2");
lVertical.addView(txtEmpName);
lVertical.addView(txtEmpDropTime);
lHori.addView(lVertical);
lHori.addView(button);
relativeLayout.addView(lHori);
linear.addView(relativeLayout);
}
The problem is I want all the buttons to be placed below the click button.
But I get output like this
How can I place all Button with text Button below the Click button?
If you two do with xml than it's so simple just make a layout which you want after click on click button after that set visibility gone for all layout accept click button next in Java on button click you can call visibility view to make that layout ...
Hope so it will works for you..
You can create a LinearLayout lButton:
LinearLayout lButton = new LinearLayout(this);
lButton.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
then set its gravity as Gravity.END
lButton.setGravity(Gravity.END)
and add the button into it
lButton.addView(button);
lHori.addView(lVertical);
lHori.addView(lButton);

Setting a layout to view.setEnabled(false) does not disable all child views

I have a layout with several nested relative layouts. Within the nested layouts I have form elements, such as TextViews, EditTexts and Buttons. The code is abbreviated just for this example:
Context con;
LinearLayout survey = new LinearLayout();
RelativeLayout question = new RelativeLayout();
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Button btnAnswer = new Button(con);
btnAnswer.setId(GlobalVars.getLatestId());
btnAnswer.addParams(params);
question.addView(btnAnswer);
TextView tvBtnLabel = new TextView(con);
btnAnswer.setId(GlobalVars.getLatestId());
tvBtnLabel.setText("Some Label");
tvBtnLabel.addParams(params);
question.addView(tvBtnLabel);
survey.addView(question);
question.setEnabled(false);
//^^^^does not set child views to disabled state
When I set the entire nested Relative Layout to false, the Button and the TextView are not disabled. I have to go in and set each child view to disabled individually. Bug in android? Is there a maximum nesting limit for disabling views? I've checked the state and the relative layouts are indeed set to disabled.
Try this:
Context con;
LinearLayout survey = new LinearLayout(con);
survey.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
RelativeLayout question = new RelativeLayout(con);
question.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Button btnAnswer = new Button(con);
btnAnswer.setId(GlobalVars.getLatestId());
btnAnswer.addParams(params);
question.addView(btnAnswer);
TextView tvBtnLabel = new TextView(con);
btnAnswer.setId(GlobalVars.getLatestId());
tvBtnLabel.setText("Some Label");
tvBtnLabel.addParams(params);
question.addView(tvBtnLabel);
survey.addView(question);
[UPDATE]
for (int i = 0; i < question.getChildCount(); i++) {
View child = question.getChildAt(i);
child.setEnabled(false);
}
Hope this help!

Adding Buttons dynamically in RelativeLayout to LinearLayout

When the user inputs a word, he creates a number of Buttons equal to the length of the word. For example: if user inputs "aaaa" he will create 4 Buttons, side by side, in the first row. Then if the user enters "bb" he will create 2 Buttons, side by side, in the second row. And "ccc" he creates 3 Buttons...
Image to demonstrate:
I dynamically create a RelativeLayout, then dynamically add Buttons to that layout. And finally I add the RelativeLayout to my existing LinearLayout. But the problem is, only one Button is added per row. And my program currently looks like this:
Can someone please me fix this problem?
CODE:
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll_bttn_words);
final LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
button_test.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
RelativeLayout relativeLayout = new RelativeLayout(view.getContext());
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
int size = enter_txt.getText().toString().length(); //the user input number of buttons
int id = 1;
for (int i=0; i<size; i++)
{
Button myButton = new Button(view.getContext());
myButton.setBackgroundResource(R.drawable.button);
myButton.setId(id);
rlp.addRule(RelativeLayout.RIGHT_OF, myButton.getId());
relativeLayout.addView(myButton, rlp);
id++;
}
linearLayout.addView(relativeLayout, llp);
rlp.addRule(RelativeLayout.RIGHT_OF, myButton.getId());
This line says that myButton should be added to right of myButton, which doesn't make any sense.
simple way to resolve this is to use the following line instead
rlp.addRule(RelativeLayout.RIGHT_OF, myButton.getId()-1);
But this isn't the best way to do this, you should use LinearLayout with horizontal orientation instead.
The structure should be simple
Just need to add your buttons in 3 different linear layout with orientation horizontal.
Like
<Relative layout>{
<LinearLayout global container with vertical orientation >{
<LinearLayout for 'a' type buttons container with horizontal orientation>
<LinearLayout for 'b' type buttons container with horizontal orientation>
<LinearLayout for 'c' type buttons container with horizontal orientation>
}
}
You guys are right. It is much easier using a LinearLayout. For those interested
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll_bttn_words);
final LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
button_test.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
LinearLayout linearLayout2 = new LinearLayout(view.getContext());
linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams rlp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
int size = enter_txt.getText().toString().length();
for (int i=0; i<size; i++)
{
Button myButton = new Button(view.getContext());
myButton.setBackgroundResource(R.drawable.button);
linearLayout2.addView(myButton, rlp);
}
linearLayout.addView(linearLayout2, llp);

how to arrange button at bottom of scrollview programatically

Here is my code to display button at bottom of scroll view programmatically.but only scrollview is displaying.button is not displaying on the screen.how to fix this.
LinearLayout ll = new LinearLayout(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
ll.setLayoutParams(lp);
ScrollView scrollView = new ScrollView(this);
TableLayout resultLayout = new TableLayout(this);
resultLayout.setStretchAllColumns(true);
resultLayout.setShrinkAllColumns(true);
scrollView.addView(resultLayout);
ll.addView(scrollView);
Button btn = new Button(this);
ViewGroup.LayoutParams blp = new ViewGroup.LayoutParams(
LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
btn.setLayoutParams(blp);
btn.setText("Click Me");
//ll.addView(rl1);
ll.addView(btn);
setContentView(ll);
screen of scroll view which contains
Try this approach... Change your ll (Linear Layout) to relative layout then put the properties for button to attach at layout bottom and and for scroll view to attach above button....hope you get my point....
Change your current layout LinearLayout with RelativeLayout and use this params. it will work
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
Just Add the Footer to the Scroll View and then get the button as you wish.
Button btn = new Button(this);
ViewGroup.LayoutParams blp = new ViewGroup.LayoutParams(
LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
btn.setLayoutParams(blp);
btn.setText("Click Me");
Then Add the view to your Scroll View.
ll.addFooterView(btn);

Android button layout

I have recently coded my button to be aligned to the right of the screen and it seems to not want to work.
I have also checked to see if my parent layout is set to cover the whole width of the screen and it is.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//Vertical Layout - For the layout of the newSheetLayout.
newSheetLayoutV = new LinearLayout(this);
newSheetLayoutV.setOrientation(LinearLayout.VERTICAL);
//Horizontal layout - nested in Vertical layout. Used for the next, back and save buttons.
newSheetButtonLayoutH = new LinearLayout(this);
newSheetButtonLayoutH.setOrientation(LinearLayout.HORIZONTAL);
//Vertical Layout - For the layout of the newSheetLayout.
dataShowV = new LinearLayout(this);
dataShowV.setOrientation(LinearLayout.VERTICAL);
//Horizontal layout - nested in the dataShow V. Used for the data entry objects.
dataShowH = new LinearLayout(this);
dataShowH.setOrientation(LinearLayout.HORIZONTAL);
//Next button.
nextButton = new Button(this);
nextButton.setText("NEXT >");
nextButton.setOnClickListener(nextListener);
//Back button.
backButton = new Button(this);
backButton.setText("< BACK");
backButton.setOnClickListener(backListener);
backButton.setEnabled(false);
//Save button.
saveButton = new Button(this);
saveButton.setText("Save");
saveButton.setOnClickListener(saveListener);
saveButton.setEnabled(false);
//Addition of the buttons to the button view in order that needs to be seen.
newSheetButtonLayoutH.addView(backButton);
newSheetButtonLayoutH.addView(nextButton);
newSheetButtonLayoutH.addView(saveButton);
//Layout Param's for the buttons.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
newSheetButtonLayoutH.setLayoutParams(params);
//Set save to anchor right.
LinearLayout.LayoutParams saveButtonParam = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
saveButtonParam.gravity = Gravity.RIGHT;
saveButton.setLayoutParams(saveButtonParam);
//Add all the layout Views to the main layout view.
newSheetLayoutV.addView(dataShowV);
newSheetLayoutV.addView(newSheetButtonLayoutH);
newSheetLayoutV.setGravity(Gravity.BOTTOM);
setContentView(newSheetLayoutV);
}
If it is something simple and I'm very blind to the solution, I will punish myself accordingly.
Thank you for your help.
try
saveButton.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,Gravity.RIGHT);
if you are using xml and your need is not to do it in dynamic way then do
android:layout_gravity="right"
Edit:
i think this is what you want
LinearLayout newSheetLayoutV,dataShowV,dataShowH,newSheetButtonLayoutH,newlayout;
Button nextButton,backButton,saveButton;
//RelativeLayout ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
newSheetLayoutV = new LinearLayout(this);
newSheetLayoutV.setOrientation(LinearLayout.VERTICAL);
//Horizontal layout - nested in Vertical layout. Used for the next, back and save buttons.
newSheetButtonLayoutH = new LinearLayout(this);
newSheetButtonLayoutH.setOrientation(LinearLayout.HORIZONTAL);
newlayout = new LinearLayout(this);
newlayout.setOrientation(LinearLayout.VERTICAL);
newlayout.setGravity(Gravity.RIGHT);
newlayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
//newSheetButtonLayoutH = new RelativeLayout(this);
//Vertical Layout - For the layout of the newSheetLayout.
dataShowV = new LinearLayout(this);
dataShowV.setOrientation(LinearLayout.VERTICAL);
//Horizontal layout - nested in the dataShow V. Used for the data entry objects.
dataShowH = new LinearLayout(this);
dataShowH.setOrientation(LinearLayout.HORIZONTAL);
//Next button.
nextButton = new Button(this);
nextButton.setText("NEXT >");
//nextButton.setOnClickListener(nextListener);
//Back button.
backButton = new Button(this);
backButton.setText("< BACK");
//backButton.setOnClickListener(backListener);
backButton.setEnabled(false);
//Save button.
saveButton = new Button(this);
saveButton.setText("Save");
//saveButton.setOnClickListener(saveListener);
saveButton.setEnabled(false);
LinearLayout.LayoutParams saveButtonParam = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//saveButtonParam.gravity = Gravity.RIGHT;
saveButton.setLayoutParams(saveButtonParam);
//Addition of the buttons to the button view in order that needs to be seen.
newSheetButtonLayoutH.addView(backButton);
newSheetButtonLayoutH.addView(nextButton);
newlayout.addView(saveButton);
newSheetButtonLayoutH.addView(newlayout);
//Layout Param's for the buttons.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
newSheetButtonLayoutH.setLayoutParams(params);
//Set save to anchor right.
//Add all the layout Views to the main layout view.
newSheetLayoutV.addView(dataShowV);
newSheetLayoutV.addView(newSheetButtonLayoutH);
newSheetLayoutV.setGravity(Gravity.BOTTOM);
setContentView(newSheetLayoutV);
}
Try giving RelativeLayout params
RelativeLayout.LayoutParams rel_lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rel_lp.addRule(RelativeLayout.ALIGN_RIGHT);
rel_lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
btn.setLayoutParams(rel_lp);
Try setting the layout_gravity of LinearLayout instead of your Button.

Categories

Resources