아래 그림과 같이 타블렛을 세 개의 개별 화면으로 분할해야하는 응용 프로그램을 설계하고 있습니다. 각 화면에 그림이 표시되며이 그림을 세로로 스 와이프하면 다음 그림으로 이동합니다. 조각을 사용하여이 작업을 수행했으며 지금까지는 그림과 같이 한 화면에 3 개의 조각을 표시했습니다. 각 조각은 위 또는 아래로 스 와이프에 반응합니다. 뷰 사이퍼와 애니메이션을 사용하여 이미지를 스 와이프했습니다.하나의 화면에서 세 조각을 사용하는 방법은 무엇입니까?
01-08 15:52:05.870: E/AndroidRuntime(4061): FATAL EXCEPTION: main
01-08 15:52:05.870: E/AndroidRuntime(4061): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.david.fragmenttest/com.david.fragmenttest.MainFragment}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
내 조각 클래스에 추가 할 때 코드는 그 자체로 잘 작동하지만 : 내 응용 프로그램에이 코드를 추가 할 때 그러나 그것은 아래 표와 같이 내 로그 캣에 부풀려 예외가 crash.I에 발생 ? 나는 그것의 가능하면 아는 사람 위의 error.Does이 조각 클래스 내에서 viewflipper 및 애니메이션을 사용하여 얻을 난 어쩌면이 길을 잘못 접근하고 있습니까 감사
메인 클래스 :
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
프래그먼트
public class ImageTwo extends Fragment {
private ViewFlipper mViewFlipper;
private int mSpeed;
private int mCount;
private int mFactor;
private boolean mAnimating;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.pic_two, container, false);
mViewFlipper = (ViewFlipper) getView().findViewById(R.id.view_flipper);
mAnimating = false;
mCount = 0;
mSpeed = 0;
final GestureDetector gesture = new GestureDetector(getActivity(),
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return true;
}
private Runnable r1 = new Runnable() {
@Override
public void run() {
up();
if (mCount < 1) {
mAnimating = false;
} else {
Handler h = new Handler();
h.postDelayed(r1, mSpeed);
}
}
};
private Runnable r2 = new Runnable() {
@Override
public void run() {
down();
if (mCount < 1) {
mAnimating = false;
} else {
Handler h = new Handler();
h.postDelayed(r2, mSpeed);
}
}
};
@Override
public boolean onFling(MotionEvent start,
MotionEvent finish, float xVelocity, float yVelocity) {
try {
if (mAnimating)
return true;
mAnimating = true;
mCount = (int) Math.abs(yVelocity)/900;
mFactor = (int) 300/mCount;
mSpeed = mFactor;
if (yVelocity > 0) {
// down
Handler h = new Handler();
h.postDelayed(r2, mSpeed);
} else {
// up
Handler h = new Handler();
h.postDelayed(r1, mSpeed);
}
// ((TextView)findViewById(R.id.velocity)).setText("VELOCITY => "+Float.toString(yVelocity));
} catch (ArithmeticException e) {
// swiped too slow doesn't register
mAnimating = false;
}
return true;
}
private void up() {
mCount--;
mSpeed += mFactor;
Animation inFromBottom = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromBottom
.setInterpolator(new AccelerateInterpolator());
inFromBottom.setDuration(mSpeed);
Animation outToTop = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f);
outToTop.setInterpolator(new AccelerateInterpolator());
outToTop.setDuration(mSpeed);
mViewFlipper.clearAnimation();
mViewFlipper.setInAnimation(inFromBottom);
mViewFlipper.setOutAnimation(outToTop);
if (mViewFlipper.getDisplayedChild() == 0) {
mViewFlipper.setDisplayedChild(2);
} else {
mViewFlipper.showPrevious();
}
}
private void down() {
mCount--;
mSpeed += mFactor;
Animation outToBottom = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 1.0f);
outToBottom
.setInterpolator(new AccelerateInterpolator());
outToBottom.setDuration(mSpeed);
Animation inFromTop = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromTop.setInterpolator(new AccelerateInterpolator());
inFromTop.setDuration(mSpeed);
mViewFlipper.clearAnimation();
mViewFlipper.setInAnimation(inFromTop);
mViewFlipper.setOutAnimation(outToBottom);
if (mViewFlipper.getDisplayedChild() == 0) {
mViewFlipper.setDisplayedChild(2);
} else {
mViewFlipper.showPrevious();
}
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
});
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gesture.onTouchEvent(event);
}
});
return view;
}
}
조각 레이아웃에 대한
main.xml에
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<fragment
android:id="@+id/imOne"
android:name="com.david.ImageOne"
android:layout_width="400dp"
android:layout_height="fill_parent" />
<fragment
android:id="@+id/imTwo"
android:name="com.david.ImageTwo"
android:layout_width="400dp"
android:layout_height="fill_parent" />
<fragment
android:id="@+id/imThree"
android:name="com.david.ImageThree"
android:layout_width="400dp"
android:layout_height="fill_parent" />
</LinearLayout>
클래스 -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bus_1" />
</LinearLayout>
왜 'ViewPager'를 사용하지 않습니까? – CommonsWare
사진을 세로로 움직이고 가로로 스 와이프하지 않기 때문에 – DMC