根据缩略图更改SurfaceView图像

时间:2012-02-14 12:03:40

标签: android

到目前为止,我有一个Activity,其中有一系列缩略图,点击缩略图后会打开Camera Activity,其中SurfaceView正在下面的XML中设置:

我需要一种能够更改SurafceView的方法,具体取决于之前Activity中选择的缩略图,我将缩略图设置为buttons。我已经为每个按钮指定了与SurfaceView上应使用的图像名称相同的ID,因此可以使用按钮ID并更改下面的RelativeLayout背景。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/overlay"
android:gravity="bottom"
android:orientation="vertical" >

<Button
    android:id="@+id/takepicture"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_margin="10px"
    android:layout_marginBottom="10dp"
    android:background="@drawable/capture" />

</RelativeLayout>

爪哇:

View viewControl = controlInflater.inflate(R.layout.control, null);
    LayoutParams layoutParamsControl 
        = new LayoutParams(LayoutParams.FILL_PARENT, 
        LayoutParams.FILL_PARENT);
    this.addContentView(viewControl, layoutParamsControl);

1 个答案:

答案 0 :(得分:1)

启动Camera活动时,将所需背景的ID放入intent的extras包中,如下所示:

intent.putExtra("backgroundId", backgroundId);
startActivity(intent);

在第二个活动中,您从意图中检索背景ID并将其分配给根视图的背景:

@Override
public void onCreate(Bundle bundle) {
     ...
     int backgroundId = getIntent().getIntExtra("backgroundId", 0);
     viewControl.setBackgroundResouce(backgroundId);
     ...
}