为什么Gravity.CENTER_VERTICAL不是垂直居中视图?

时间:2013-05-20 10:47:19

标签: android

我正在尝试在其父View的中心(垂直)View创建一个RelativeLayout

我尝试了View.setGravity(Gravity.VERTICAL);

但它不能很好地工作,视图的位置略低于中心。我的代码肯定有问题,但我似乎无法发现妨碍视图处于中心位置的错误。

        ....

        initArrayViews[a] = new RelativeLayout(context);
        initArrayViews[a].setBackgroundResource(R.drawable.bg);
        initArrayViews[a].setLayoutParams(screensize);

        inInit.addView(initArrayViews[a]);

         RelativeLayout theone = new RelativeLayout(context);
         theone.setBackgroundResource(R.drawable.layer1);
         theone.setLayoutParams(screensize);
         initArrayViews[a].addView(theone);
         theone.setGravity(Gravity.CENTER_VERTICAL);
         params = new LinearLayout.LayoutParams(this.getWidth(), this.getHeight());

         LinearLayout X = new LinearLayout(context);
         X.setLayoutParams(params);
         X.setBackgroundResource(R.drawable.roundr);
         X.setOrientation(LinearLayout.VERTICAL);
         theone.addView(X);

0 个答案:

没有答案
相关问题