2012-02-14 92 views
1

到目前为止,我有一个Activity那里有一个选择的缩略图,一旦缩略图点击它打开了Camera Activity与在下面的XML被设置SurfaceView变化SurfaceView图片根据缩略图

我需要一种方法能够更改SurafceView,具体取决于在先前的Activity中选择了哪个缩略图我的缩略图设置为buttons。我给每个按钮相同的ID,因为它应该在SurfaceView使用图像名称,以便有没有办法把按钮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> 

的Java:

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

你开始一个新的活动或只是设置新的布局? – 2012-02-16 12:54:19

+0

Matt,你忘记了添加Camera Activity xml布局。除此之外,你不太清楚你想用按钮ID做什么。 – 2012-02-22 08:07:15

回答

1

当启动摄像头活动,把你想要进入的意图的额外的背景ID捆绑,像这样:

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

在第二活动你从你的意图检索背景ID,并将其分配到根视图的背景:

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