我遇到了一个问题,当我尝试给一个LinearLayout的负左边距。
负边距不会出现。
这里是我的代码Android负边距不起作用
HorizontalScrollView hview = new HorizontalScrollView(context); // HorizontalScrollView is the outer view
RelativeLayout.LayoutParams hs_lot_params = new RelativeLayout.LayoutParams(164, 164);
hs_lot_params.setMargins(100, 100, 0, 0); // set the positions
ImageView image = new ImageView(context);
image.setBackgroundResource(R.drawable.leder);
LinearLayout.LayoutParams img_lot_params = new LinearLayout.LayoutParams(164, 164);
img_lot_params.setMargins(0, 0, 0, 0);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(164, 164);
layoutParams.setMargins(-132, 0, 0, 0);
ll.addView(image, img_lot_params);
hview.addView(ll, layoutParams);
注:我的计划是从左至右滚动图像。
首先,图像的左边部分是隐藏的,可以滚动到右侧看到完整的图像
原因是因为在之前的Android SDK版本中,允许使用负边界(最高2.2?)。 –
那我们如何替换AbsoluteLayout而不使用负边距? –
使用'translateX'。 – nhaarman