Why does setMargins() not work on buttons?
up vote
0
down vote
favorite
Why does setMargins() not work on buttons?
Screen
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GridLayout gridLayout = new GridLayout(this);
gridLayout.setRowCount(5);
gridLayout.setColumnCount(7);
setContentView(gridLayout);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100,100);
layoutParams.setMargins(10,10,10,10);
for(int i=1;i<31;i++) {
Button button = new Button(this);
button.setText(String.valueOf(i));
button.setTextSize(18);
button.setBackgroundResource(R.drawable.button);
gridLayout.addView(button,layoutParams);
}
}
}
android
add a comment |
up vote
0
down vote
favorite
Why does setMargins() not work on buttons?
Screen
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GridLayout gridLayout = new GridLayout(this);
gridLayout.setRowCount(5);
gridLayout.setColumnCount(7);
setContentView(gridLayout);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100,100);
layoutParams.setMargins(10,10,10,10);
for(int i=1;i<31;i++) {
Button button = new Button(this);
button.setText(String.valueOf(i));
button.setTextSize(18);
button.setBackgroundResource(R.drawable.button);
gridLayout.addView(button,layoutParams);
}
}
}
android
1
While it is fine to post a screenshot of an application / web page, posting screenshot of code should be avoided for many reasons. Please edit your question to add the relevant code. If possible produce a MCVE
– Gabriel Devillers
Nov 7 at 19:20
Can you please put your code in your question.
– chetan mahajan
Nov 7 at 19:39
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Why does setMargins() not work on buttons?
Screen
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GridLayout gridLayout = new GridLayout(this);
gridLayout.setRowCount(5);
gridLayout.setColumnCount(7);
setContentView(gridLayout);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100,100);
layoutParams.setMargins(10,10,10,10);
for(int i=1;i<31;i++) {
Button button = new Button(this);
button.setText(String.valueOf(i));
button.setTextSize(18);
button.setBackgroundResource(R.drawable.button);
gridLayout.addView(button,layoutParams);
}
}
}
android
Why does setMargins() not work on buttons?
Screen
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GridLayout gridLayout = new GridLayout(this);
gridLayout.setRowCount(5);
gridLayout.setColumnCount(7);
setContentView(gridLayout);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100,100);
layoutParams.setMargins(10,10,10,10);
for(int i=1;i<31;i++) {
Button button = new Button(this);
button.setText(String.valueOf(i));
button.setTextSize(18);
button.setBackgroundResource(R.drawable.button);
gridLayout.addView(button,layoutParams);
}
}
}
android
android
edited Nov 7 at 20:30
forpas
4,4441216
4,4441216
asked Nov 7 at 19:11
Poltorashka
12
12
1
While it is fine to post a screenshot of an application / web page, posting screenshot of code should be avoided for many reasons. Please edit your question to add the relevant code. If possible produce a MCVE
– Gabriel Devillers
Nov 7 at 19:20
Can you please put your code in your question.
– chetan mahajan
Nov 7 at 19:39
add a comment |
1
While it is fine to post a screenshot of an application / web page, posting screenshot of code should be avoided for many reasons. Please edit your question to add the relevant code. If possible produce a MCVE
– Gabriel Devillers
Nov 7 at 19:20
Can you please put your code in your question.
– chetan mahajan
Nov 7 at 19:39
1
1
While it is fine to post a screenshot of an application / web page, posting screenshot of code should be avoided for many reasons. Please edit your question to add the relevant code. If possible produce a MCVE
– Gabriel Devillers
Nov 7 at 19:20
While it is fine to post a screenshot of an application / web page, posting screenshot of code should be avoided for many reasons. Please edit your question to add the relevant code. If possible produce a MCVE
– Gabriel Devillers
Nov 7 at 19:20
Can you please put your code in your question.
– chetan mahajan
Nov 7 at 19:39
Can you please put your code in your question.
– chetan mahajan
Nov 7 at 19:39
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
if you use ConstraintLayout in your layout you should make sure your button had chain from that side you want have margin
example
<Button
android:id="@+id/btn"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
/>
if you dont write
app:layout_constraintBottom_toBottomOf="parent"
in your Button's tag you cant set margin from bottom
and otherside like this.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
if you use ConstraintLayout in your layout you should make sure your button had chain from that side you want have margin
example
<Button
android:id="@+id/btn"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
/>
if you dont write
app:layout_constraintBottom_toBottomOf="parent"
in your Button's tag you cant set margin from bottom
and otherside like this.
add a comment |
up vote
0
down vote
if you use ConstraintLayout in your layout you should make sure your button had chain from that side you want have margin
example
<Button
android:id="@+id/btn"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
/>
if you dont write
app:layout_constraintBottom_toBottomOf="parent"
in your Button's tag you cant set margin from bottom
and otherside like this.
add a comment |
up vote
0
down vote
up vote
0
down vote
if you use ConstraintLayout in your layout you should make sure your button had chain from that side you want have margin
example
<Button
android:id="@+id/btn"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
/>
if you dont write
app:layout_constraintBottom_toBottomOf="parent"
in your Button's tag you cant set margin from bottom
and otherside like this.
if you use ConstraintLayout in your layout you should make sure your button had chain from that side you want have margin
example
<Button
android:id="@+id/btn"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
/>
if you dont write
app:layout_constraintBottom_toBottomOf="parent"
in your Button's tag you cant set margin from bottom
and otherside like this.
answered Nov 7 at 19:29
Ardalan Sajedi
11
11
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53196232%2fwhy-does-setmargins-not-work-on-buttons%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
While it is fine to post a screenshot of an application / web page, posting screenshot of code should be avoided for many reasons. Please edit your question to add the relevant code. If possible produce a MCVE
– Gabriel Devillers
Nov 7 at 19:20
Can you please put your code in your question.
– chetan mahajan
Nov 7 at 19:39