在android中动态移动图像
这是我的应用程序中的oncreate在android中动态移动图像,android,Android,这是我的应用程序中的oncreate @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); getWindow().setFo
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
controlInflater = LayoutInflater.from(getBaseContext());
viewControl = controlInflater.inflate(R.layout.control, null);
image =(ImageView) viewControl.findViewById(R.id.img);
LayoutParams layoutParamsControl
= new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);
}
control.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
/>
</LinearLayout>
但现在图像将消失两秒钟。我做错了什么。
请任何人帮忙。
实际上,我想在加速计更改时移动图像。如果使用动画,则图像在完成动画后将返回到开始位置 如果你想达到这样的效果,那就增加动画的持续时间 或者,如果要在没有动画的情况下将图像从一个位置缩放到另一个位置 删除动画,只需使用按钮的单击方法
ImageView.scrollBy(scrollByX, scrollByY);
有关更多信息,请查看。如果您正在使用动画,则图像在完成动画后将返回到开始位置 如果你想达到这样的效果,那就增加动画的持续时间 或者,如果要在没有动画的情况下将图像从一个位置缩放到另一个位置 删除动画,只需使用按钮的单击方法
ImageView.scrollBy(scrollByX, scrollByY);
有关更多信息,请参阅