2012-02-14 91 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); 
    ... 
}