我有自己的定製ScrollView
我的layout
,其中包含一個單一FrameLayout
和所有其他View
放在它裏面的主要View
。它看起來像這樣(這是sm_layout.xml):的Java返回「滾動型只能承載一個直接子」的時候,只有一個直接子
<com.effeleven.utils.CustomScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:background="@color/white"
android:clickable="true">
<FrameLayout...>
</com.effeleven.utils.CustomScrollView>
我沒有這個例外,當我用默認的Android ScrollView
拋出。現在我需要一個自定義的,因爲我需要處理ScrollView
(我有一個mapFragment
和,我不能取代任何東西,因爲我遵循設計模式)內的滾動事件。什麼可能導致異常,因爲我的CustomScrollView
只包含一個FrameLayout,就像前面的ScrollView
一樣?
這是我CustomScrollView
類:
public class CustomScrollView extends ScrollView {
public CustomScrollView(Context context) {
super(context);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.sm_layout, this, true);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action)
{
case MotionEvent.ACTION_DOWN:
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_MOVE:
return false;
case MotionEvent.ACTION_CANCEL:
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_UP:
return false;
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
super.onTouchEvent(ev);
return true;
}
}
發佈您的'sm_layout.xml' – DeKaNszn
@DeKaNszn sm_layout.xml是我上面發佈的一個。 –