一.问题描述
在设计UI过程中,想使图片处于屏幕的特定位置(如下图1),但发现图片总是在顶端(如下图2):
图一:欲实现的界面 图二:实际的界面
二.解决办法
2.1使用setPadding
如下所示:
RelativeLayout relativeLayout =(RelativeLayout) findViewById(R.id.login);
relativeLayout.setPadding(0,40,0,0);
其中第一行表示获取到该界面的布局,第二行对该布局使用setPadding()方法,意为规定其内部控件需距该控件的距离。
2.2使用setMargin
如下所示:
ImageView applicationImageView = (ImageView) findViewById(R.id.app_imageView);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) applicationImageView