기존에 썼던 글이 오류가 나는 듯 하여 다시 작성합니다.


위에 겹쳐진 레이아웃을 onCreate에서 바로 전개한 건 아니고 별도의 OverlayView 라는 클래스에서 전개하였는데,

혹시 그것 때문에 겹쳐진 레이아웃에 위젯에 접근이 안되는 것인지 의심됩니다.


화면이 터치되면 위에 레이아웃을 겹칠 거라서 부득이 저렇게 전개했습니다.

답변 부탁 드립니다. ^^


import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.*;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
import android.widget.LinearLayout.LayoutParams;

public class LiveViewActivity extends Activity 
{
    boolean OVERLAY = false;
    private OverlayView ov;
    private Window win;
    LayoutInflater inflater;
    LinearLayout linear;
    LinearLayout.LayoutParams paramlinear;
    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 라이브뷰 전용 셋팅
        // 화면방향은 가로고정
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        // 타이틀바 표시하지 않음
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        win = getWindow();
        ov = new OverlayView(this);
        win.setContentView(ov);
        
        inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        linear = (LinearLayout)inflater.inflate(R.layout.liveviewoverlay, null);
        paramlinear = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);

        Button btn2 = (Button)findViewById(R.id.2);
        
        btn2.setOnClickListener(new Button.OnClickListener(){
            public void onClick(View v){
                Toast.makeText(LiveViewActivity.this, "test", Toast.LENGTH_SHORT).show();
            }
        });
    }
    
    protected class OverlayView extends View{
        public OverlayView(Context context){
            super(context);
        }
        
        public void onDraw(Canvas canvas){
            canvas.drawColor(Color.LTGRAY);
            Paint pnt = new Paint();
            Bitmap bit = BitmapFactory.decodeResource(getResources(), R.drawable.ramborghini);
            canvas.drawBitmap(bit, 10, 10, null);
        }
        
        public boolean onTouchEvent(MotionEvent event){
            if(event.getAction() == MotionEvent.ACTION_DOWN){
                if(OVERLAY == false)
                {
                    win.addContentView(linear, paramlinear);
                    OVERLAY = true;
                    return true;
                }
                else{
                    win.setContentView(ov);
                    OVERLAY = false;
                }                
            }
            return false;
        }
    }
}