Android - Resize UI widget created dynamically

تعرفه تبلیغات در سایت
عنوان عکس عنوان عکس عنوان عکس عنوان عکس
عنوان عکس عنوان عکس عنوان عکس عنوان عکس
عنوان عکس عنوان عکس عنوان عکس عنوان عکس
عنوان عکس عنوان عکس عنوان عکس عنوان عکس
عنوان عکس عنوان عکس عنوان عکس عنوان عکس

آرشیو مطالب


یافته ها در جستجو

    امکانات وب

    برچسب ها

    Vote count: 0

    I try to create a button dynamically with in Java and add it some constraints to position it in the center of my constrainLayout. So I write this code:

    import android.os.Bundle;
    import android.widget.Button;
    public class SelectGameActivity extends Activity {
        protected void onCreate(Bundle savedInstanceState) {
        ConstraintSet constraintSet = new ConstraintSet();
        ConstraintLayout constraintLayout = findViewById(;
        Button button = new Button(this);
        constraintSet.connect(button.getId(), ConstraintSet.LEFT,, ConstraintSet.LEFT);
        constraintSet.connect(button.getId(), ConstraintSet.RIGHT,, ConstraintSet.RIGHT);
        constraintSet.connect(button.getId(), ConstraintSet.TOP,, ConstraintSet.TOP);
        constraintSet.connect(button.getId(), ConstraintSet.BOTTOM,, ConstraintSet.BOTTOM);

    It works but the button fills all the screen:

    enter image description here

    I think it is because my button doesn't have any specific height and width. I tried several codes to give it a size but no effect. Could someone give me some hints to resize my button correctly ?

    Thank you very much !


    asked 1 min ago

  • مطالب مرتبط
  • Android EventBus not working
  • How to dynamically load urls (in the form if images) in collection view in swift ios?
  • Capture from camera Image is not clear(Blurry) in Android
  • Android : There's no route in routing table, but still online. Why?
  • windowSoftInputMode=“adjustResize” not working after changing visibility of child
  • SSL Certificate Pinning for Android WebView using React Native including versions > 0.44
  • نویسنده : استخدام کار بازدید : 7 تاريخ : دوشنبه 27 شهريور 1396 ساعت: 1:53
    برچسب‌ها :