在某些设备中,ImageView尺寸不会更改

时间:2018-12-11 11:22:51

标签: android imageview android-relativelayout

我正在以编程方式创建一些ImageView,以将它们用作自定义图像滑块的点,但是由于某些原因,图像的尺寸在某些设备中不会改变。

这是我用来生成这些ImageView并将它们彼此对齐的代码:

private void drawMainImageDots(RelativeLayout layout, int total)
{
    int distance = 0;
    int step = 25;
    for (int i=0; i<total; i++)
    {
        ImageView imageView = new ImageView(getActivity());
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(20, 20);

        if (i==0)
        {
            lp.setMargins(0,0,0,0);
            imageView.setImageResource(R.drawable.dotselected);
        }
        else
        {
            lp.setMargins(distance,0,0,0);
            imageView.setImageResource(R.drawable.dotunselected);
        }

        distance = distance + step;
        imageView.setLayoutParams(lp);
        imageView.getLayoutParams().height = 20;
        imageView.getLayoutParams().width = 20;

        layout.addView(imageView);
        dotsMainImageViewList.add(imageView);
    }
}

RelativeLayout layout xml代码是:

<RelativeLayout
     android:id="@+id/mainimagegallerydotscon"
     android:layout_width="wrap_content"
     android:layout_height="20dp"
     android:layout_centerHorizontal="true"
     android:layout_alignParentBottom="true"
     android:layout_marginBottom="5dp"/>

我的代码有问题吗?

0 个答案:

没有答案