Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓负保证金不起作用_Android - Fatal编程技术网

Android 安卓负保证金不起作用

Android 安卓负保证金不起作用,android,Android,我在尝试为线性布局提供负左边距时遇到了一个问题。 不显示负边距。 这是我的密码 HorizontalScrollView hview = new HorizontalScrollView(context); // HorizontalScrollView is the outer view RelativeLayout.LayoutParams hs_lot_params = new RelativeLayout.LayoutParams(164, 164); hs_lot_params

我在尝试为线性布局提供负左边距时遇到了一个问题。
不显示负边距。
这是我的密码

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);
注意:我的计划是从左向右滚动图像。

首先,图像的左半部分是隐藏的,可以向右滚动查看完整图像

负边距应在
线性布局
相对布局
中工作。您可能需要使用
scrollBy(int x,int y)
scrollTo(int x,int y)
滚动
水平滚动视图
,以实现您描述的“窥视和滚动”效果


还要记住,使用原始像素单位通常是个坏主意,因为实际大小取决于屏幕的像素密度。首选
dp
测量值。

原因是在以前版本的Android SDK中允许负边距(高达2.2?)。那么我们如何在不使用负边距的情况下替换AbsoluteLayout?@Amitrajapati在ICS上测试了负边距,它运行良好负边距似乎一直存在问题,尽管android团队的Romain Guy说它在LinearLayout post 2.2上运行得很好(
 ViewGroup.MarginLayoutParams params =
 (ViewGroup.MarginLayoutParams)view.getLayoutParams(); params.topMargin = -100;