Percentage width in a RelativeLayout

后端 未结 14 1973
遥遥无期
遥遥无期 2020-11-22 13:54

I am working on a form layout for a Login Activity in my Android App. The image below is how I want it to look like:

14条回答
  •  -上瘾入骨i
    2020-11-22 14:05

    I have solved this creating a custom View:

    public class FractionalSizeView extends View {
      public FractionalSizeView(Context context, AttributeSet attrs) {
        super(context, attrs);
      }
    
      public FractionalSizeView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
      }
    
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int width = MeasureSpec.getSize(widthMeasureSpec);
        setMeasuredDimension(width * 70 / 100, 0);
      }
    }
    

    This is invisible strut I can use to align other views within RelativeLayout.

提交回复
热议问题