저는 2 개의 이미지가있는 작은 프로그램을 가지고 있습니다. 지금은 이미지를 클릭 할 때 각 이미지의 OnTouch 이벤트를 보이고 있습니다. 보이지 않는 이미지로 설정되어 있습니다. 이것은 잘 작동하고 있습니다 ..하지만 주 활동에 이것을 가지고있는 것은 지저분 해지고 있습니다.Android 일반 질문
TestView를 만들었습니다. 주 활동에있는 코드를 testView로 옮기고 싶습니다. OnTouch 이벤트를 넣고 거기에서 어떻게 할 것인가? OnTouch 이벤트를 넣을 위치와 이미지 뷰를 내 testView에서 가져 오는 방법을 알지 못합니다. .. 나는 "testView extends View"클래스에서 그 (것)들을 그리는 방법을 모른다. .. 내가 그것을 조직하도록 도울 수 있니?
public class TestView extends View{
public TestView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public TestView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public TestView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
}
난 그냥 내가 거기에서 작동하도록 그것을 구성을 다시 할 수있는 방법 시험보기로 이동하는 경우, 알고 싶은public class GameActivity extends Activity {
/** Called when the activity is first created. */
public int ColorId;
public boolean isUserTurn = false;
public int globalIndex = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myviewlay);
final ImageView image1= (ImageView)findViewById(R.id.ImageView03);
image1.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
try {
Thread.sleep(200);
ColorId = 1;
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
image1.setVisibility(View.INVISIBLE);
}
else
{
image1.setVisibility(View.VISIBLE);
}
//return super.onTouchEvent(event);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
});
final ImageView image2= (ImageView)findViewById(R.id.ImageView02);
image2.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
try {
Thread.sleep(200);
ColorId = 2;
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
image2.setVisibility(View.INVISIBLE);
}
else
{
image2.setVisibility(View.VISIBLE);
}
//return super.onTouchEvent(event);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
});
. 나는
당신이 당신의TestView
에
onTouchListener
을 구현하는 데 필요한 onTouch 이벤트의 당신에게
감사합니다, 분명하지 않다 유일한 것은 내가에있는 OnTouch 함수 내 ImageViews을 배치 할 곳이다 : 명확하지 충분히 경우
, 뭔가 말 내 주요 활동 ...? : – user710502
레이아웃으로 XML 레이아웃을 만들 수 있습니다 레이아웃에서 사용자 정의보기를 사용할 때 (예 :와 같은) 전체 클래스 경로를 지정해야합니다. 당신의 활동은 단지'setContentView()'를 호출했다. –
JQCorreia