所以我一直在尝试使用谷歌地图精简版fragment
里面一个scrollView
我无法显示地图。删除后scrollView
然后将片段单独保留,现在您就可以看到地图了。我只是想了解为什么会这样,以及是否有任何方法可以让这个片段显示在我的滚动视图的末尾。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.joe.goout.EventDetails">
<ImageView
android:src="@mipmap/park1"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:id="@+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/imageView"
android:id="@+id/scrollView"
android:fillViewport="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:id="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</ScrollView>
</RelativeLayout>
首先您需要创建一个自定义ScrollView
类,如下所示。
public class CustomScrollView extends ScrollView {
public CustomScrollView(Context context) {
super(context);
}
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
//Log.i("CustomScrollView", "onInterceptTouchEvent: DOWN super false" );
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_MOVE:
return false; // redirect MotionEvents to ourself
case MotionEvent.ACTION_CANCEL:
// Log.i("CustomScrollView", "onInterceptTouchEvent: CANCEL super false" );
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_UP:
//Log.i("CustomScrollView", "onInterceptTouchEvent: UP super false" );
return false;
default:
//Log.i("CustomScrollView", "onInterceptTouchEvent: " + action );
break;
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
super.onTouchEvent(ev);
//Log.i("CustomScrollView", "onTouchEvent. action: " + ev.getAction() );
return true;
}
}
然后使用CustomScrollView
类而不是ScrollView
.
<CustomScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView">
</CustomScrollView>
你就完成了! :D
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)