【问题标题】:Shifted image when inflate ImageButtons膨胀 ImageButtons 时移动的图像
【发布时间】:2019-07-11 12:04:34
【问题描述】:

我的应用程序中有一个活动,我必须在其中为 ImageButtons 充气。起初我认为它运行良好,但注意到整个视图向下移动。我做错了吗?

我尝试更改 XML 模板的一些功能,但没有解决问题或工作。

// Retrieving view's item
    LinearLayout linear = findViewById(R.id.linear_layout_existing_picto);

// Retrieving fields from R.drawable
    Field[] fields = R.drawable.class.getFields();

// Sorting drawables by name and inserting into the scrollView
    for (final Field field : fields) {
        try {
            if (field.getName().startsWith("dra_")) {
        int currentResId = field.getInt(R.drawable.class);
        ImageButton imageButtonDrawable = (ImageButton) getLayoutInflater().inflate(R.layout.template_drawable, null);
        imageButtonDrawable.setImageResource(currentResId);
        imageButtonDrawable.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            Intent intent = new Intent();
            intent.putExtra("result", field.getName());
            setResult(AddExistingPictoActivity.RESULT_OK, intent);
            finish();
            }
        });
        linear.addView(imageButtonDrawable);
        }
        } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    }

【问题讨论】:

    标签: android xml android-layout android-linearlayout layout-inflater


    【解决方案1】:

    问题似乎来自LinearLayout“线性”的“layout_gravity”XML属性。只是删除它解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      • 2011-09-23
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 2019-07-28
      相关资源
      最近更新 更多