안드로이드 프로젝트를 만들고 싶습니다. 거기에 내가 다른 레이아웃에서 원활하게 움직이기를 원하는 레이아웃이 있습니다. 이 작업을 수행하기 위해 스레드를 사용하려고했습니다. 그러나 코드 결과로 레이아웃은 최종 위치로 점프하고 오프셋에서 목적지까지 부드럽게 움직이지 않습니다.android layout with thread
abs1 = (AbsoluteLayout) findViewById(R.id.absoluteLayout2);
ImageButton ib1 = (ImageButton) findViewById(R.id.imageButton1);
ib1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Runnable r = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
display(100);
display(100);
display(100);
display(100);
display(100);
display(100);
display(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void display(int i) throws InterruptedException {
AbsoluteLayout.LayoutParams param = (AbsoluteLayout.LayoutParams) abs1
.getLayoutParams();
param.x = param.x + 10;
// param.y=param.x+20;
abs1.setLayoutParams(param);
if (Thread.interrupted()) {
throw (new InterruptedException());
}
Thread.sleep(i);
}
};
r.run();
주요 파일 :
<AbsoluteLayout
android:id="@+id/absoluteLayout2"
android:layout_width="107dp"
android:layout_height="308dp"
android:layout_x="10dp"
android:layout_y="12dp"
android:background="@color/red" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="0dp"
android:background="@null"
android:src="@drawable/calendar" />
어떤 방향으로 움직여야합니까? – dumazy
스레드를 사용할 필요가 없습니다. 그냥 내 대답을 봐 – dumazy
AbsoluteLayout을 사용하지 마십시오 ... 그것은 더 이상 사용되지 않습니다 ... – Piyush