So I been trying to use google maps lite fragment inside a scrollView and I haven't be able to show the map. After removing the the scrollView and leaving the fragment by it self, now is when you can see the map. I am just trying to understand why is that and also if there is any way possible to have this fragment to show at the end of my 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>
First you need to create a custom ScrollView class, like the following.
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;
}
}
Then use the CustomScrollView class instead of ScrollView.
<CustomScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
</CustomScrollView>
And you are done! :D
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#mipmap/park1" />
<Button
android:id="#+id/shareBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="New Button" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imageView"
android:padding="15dp"
android:text="Medium Text"
android:textColor="#color/black" />
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="210dp"
android:layout_below="#id/textView"
android:layout_marginBottom="40dp"
map:cameraZoom="13"
map:liteMode="true"
map:mapType="normal"
tools:context=".EventDetails" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I solved it by adding the content into ScrollView and then wrapping the content inside of RelativeLayout.
<ScrollView android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/white"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<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_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/shareBtn"
android:layout_above="#+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Medium Text"
android:textColor="#color/black"
android:padding="15dp"
android:layout_below="#id/imageView"
android:id="#+id/textView" />
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.google.android.gms.maps.SupportMapFragment"
class="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="210dp"
android:layout_below="#id/textView"
android:layout_marginBottom="40dp"
map:cameraZoom="13"
map:mapType="normal"
map:liteMode="true"
tools:context=".EventDetails"/>
</RelativeLayout>
</ScrollView>
Related
Hi i was trying to make something like this through xml code in android studio but can't figure out how although i partially reached there but feels i am not using correct approach can someone please tell me how exactly i can make this layout through xml or java.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
tools:context="com.stocks.android.gridview.MainActivity">
<LinearLayout
android:id="#+id/linear_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:layout_width="280dp"
android:layout_height="200dp"
android:layout_marginRight="5dp"
android:layout_weight="40"
app:cardBackgroundColor="#BCE36E"
app:cardCornerRadius="4dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/img1" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_weight="60"
app:cardBackgroundColor="#8BD3FB"
app:cardCornerRadius="4dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/img2" />
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/linear_one"
android:layout_margin="5dp"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_weight="60"
app:cardBackgroundColor="#FFB637"
app:cardCornerRadius="4dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/img2" />
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="200dp"
android:layout_height="100dp"
app:cardBackgroundColor="#FB7649"
app:cardCornerRadius="4dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/img3" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="200dp"
android:layout_height="95dp"
android:layout_marginTop="5dp"
app:cardBackgroundColor="#F1F1F1"
app:cardCornerRadius="4dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/img7" />
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/linear_two">
<android.support.v7.widget.CardView
android:layout_width="280dp"
android:layout_height="200dp"
android:layout_marginRight="5dp"
android:layout_weight="60"
app:cardBackgroundColor="#F34F45"
app:cardCornerRadius="4dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/img6" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_weight="40"
app:cardBackgroundColor="#55C6FF"
app:cardCornerRadius="4dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/img4" />
</android.support.v7.widget.CardView>
</LinearLayout>
</RelativeLayout>
Make a class for the dynamic height images.
public class DynamicHeightNetworkImageView extends ImageView {
private float mAspectRatio = 1.5f;
public DynamicHeightNetworkImageView(Context context) {
super(context);
}
public DynamicHeightNetworkImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DynamicHeightNetworkImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = getMeasuredWidth();
setMeasuredDimension(measuredWidth, (int) (measuredWidth / mAspectRatio));
}
public void setAspectRatio(float aspectRatio) {
mAspectRatio = aspectRatio;
requestLayout();
}
}
and use it in your xml file
<com.dmitrymalkovich.android.xyzreader.ui.DynamicHeightNetworkImageView
android:id="#+id/thumbnail"
android:layout_width="match_parent"
android:background="#color/material_grey_300"
android:layout_height="wrap_content" />
See this github rep:https://github.com/DmitryMalkovich/make-your-app-material
I'd like to use a Google Map inside a ScrollView but it seems harder than I thought. The first time I created everything and ran the app on a tablet. On the tablet, the UI looks good the map's size and the place is perfect. When I tried it a smaller device I realized that 80% size of the map is invisible. I can scroll down until the end of the screen but there is a big empty place instead of the rest of the map.
Check the xml file below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="#+id/scrollView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:id="#+id/relativeinfo1">
<View
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_above="#+id/titleinfo"
android:layout_toRightOf="#+id/imageinfo"/>
<TextView
android:id="#+id/titleinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_toRightOf="#+id/imageinfo"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="#+id/mooobil"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="#+id/telefoneeo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:id="#+id/emailese"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:id="#+id/honlapese"/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/imageinfo"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"/>
<View
android:layout_width="wrap_content"
android:layout_height="15dp"
android:id="#+id/view1"
android:layout_below="#+id/imageinfo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cimtext"
android:textStyle="bold"
android:text="Cím: "
android:textSize="15dp"
android:textColor="#000000"
android:visibility="invisible"/>
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:id="#+id/vonal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#FFD700" />
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/vonal2"
android:background="#FFD700"/>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="#+id/relativemaplayout"
android:clickable="true"
android:background="#000000">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
</RelativeLayout>
And check the java code here:
private ScrollView mScrollView;
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_service_info,parent, false);
mScrollView = (ScrollView) v.findViewById(R.id.scrollView);
//transparentImageView = (ImageView) v.findViewById(R.id.transparent_image);
mScrollView.requestDisallowInterceptTouchEvent(true);
///// MAP /////
double glat = 0;
double glong = 0;
map = ((MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.map)).getMap();
if((si.getGpslat().length()) != 0 && (si.getGpslong().length() != 0)){
glat = Double.parseDouble(si.getGpslat());
glong = Double.parseDouble(si.getGpslong());
final LatLng CEL = new LatLng(glat,glong);
if (map!=null){
MapsInitializer.initialize(getActivity());
map.addMarker(new MarkerOptions().position(CEL));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(CEL ,18));
map.animateCamera(CameraUpdateFactory.zoomTo(18), 2000, null);
}
}else{
relmap.setVisibility(View.GONE);
}
transparentImageView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
Log.d("action","down");
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
mScrollView.requestDisallowInterceptTouchEvent(true);
Log.d("action","down");
return false;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
mScrollView.requestDisallowInterceptTouchEvent(false);
Log.d("action","up");
return true;
case MotionEvent.ACTION_MOVE:
mScrollView.requestDisallowInterceptTouchEvent(true);
Log.d("action","move");
return false;
default:
return true;
}
}
});
transparentImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getActivity(), "anyád", Toast.LENGTH_SHORT).show();
}
});
return v;
}
Is it possible to show the full map in a SrcollView without using tablets?
This is how it's look like:
Try like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:id="#+id/relativeinfo1">
<View
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_above="#+id/titleinfo"
android:layout_toRightOf="#+id/imageinfo"/>
<TextView
android:id="#+id/titleinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_toRightOf="#+id/imageinfo"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="#+id/mooobil"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="#+id/telefoneeo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:id="#+id/emailese"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:id="#+id/honlapese"/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/imageinfo"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"/>
<View
android:layout_width="wrap_content"
android:layout_height="15dp"
android:id="#+id/view1"
android:layout_below="#+id/imageinfo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cimtext"
android:textStyle="bold"
android:text="Cím: "
android:textSize="15dp"
android:textColor="#000000"
android:visibility="invisible"/>
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:id="#+id/vonal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#FFD700" />
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/vonal2"
android:background="#FFD700"/>
<RelativeLayout
android:layout_alignParentBottom="true"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity"
android:id="#+id/relativemaplayout"
android:clickable="true"
android:background="#000000">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
</RelativeLayout>
update
if still you have problem please refer this and try
Google Maps API v2 SupportMapFragment inside ScrollView - users cannot scroll the map vertically
I think it`s because of your layout_height setting for fragment.That cause some measure error.
Try set layout_height to a certain dp.
such as:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="300dp"
tools:context=".MainActivity"
android:id="#+id/relativemaplayout"
android:clickable="true"
android:background="#000000">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
class="com.google.android.gms.maps.MapFragment" />
This was the solution:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="#+id/scrollView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:id="#+id/relativeinfo1">
<View
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_above="#+id/titleinfo"
android:layout_toRightOf="#+id/imageinfo"/>
<TextView
android:id="#+id/titleinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_toRightOf="#+id/imageinfo"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="#+id/cimtext"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="#+id/mooobil"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="#+id/telefoneeo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:id="#+id/emailese"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:id="#+id/honlapese"/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/imageinfo"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"/>
<View
android:layout_width="wrap_content"
android:layout_height="15dp"
android:id="#+id/view1"
android:layout_below="#+id/imageinfo"/>
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:id="#+id/vonal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#FFD700" />
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/vonal2"
android:background="#FFD700"/>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="400dp"
tools:context=".MainActivity"
android:id="#+id/relativemaplayout"
android:clickable="true">
<fragment
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
<ImageView
android:id="#+id/transparent_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#color/transparent"
android:layout_alignTop="#+id/relativemaplayout"
android:layout_alignBottom="#+id/relativemaplayout"
android:layout_alignEnd="#+id/relativemaplayout"
android:layout_alignRight="#+id/relativemaplayout"
android:layout_alignLeft="#+id/relativemaplayout"
android:layout_alignStart="#+id/relativemaplayout"/>
</RelativeLayout>
And you need to add this to the Fragment:
transparentImageView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
Log.d("action","down");
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
mScrollView.requestDisallowInterceptTouchEvent(true);
Log.d("action","down");
return false;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
mScrollView.requestDisallowInterceptTouchEvent(false);
Log.d("action","up");
return true;
case MotionEvent.ACTION_MOVE:
mScrollView.requestDisallowInterceptTouchEvent(true);
Log.d("action","move");
return false;
default:
return true;
}
}
});
I'd like to use a Google Map inside a SrcollView. To that I need to use something like that:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="#+id/scrollView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:id="#+id/relativeinfo1">
<View
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_above="#+id/titleinfo"
android:layout_toRightOf="#+id/imageinfo"/>
<TextView
android:id="#+id/titleinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_toRightOf="#+id/imageinfo"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="#+id/mooobil"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="#+id/telefoneeo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:id="#+id/emailese"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:id="#+id/honlapese"/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/imageinfo"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"/>
<View
android:layout_width="wrap_content"
android:layout_height="15dp"
android:id="#+id/view1"
android:layout_below="#+id/imageinfo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cimtext"
android:textStyle="bold"
android:text="Cím: "
android:textSize="15dp"
android:textColor="#000000"
android:visibility="invisible"/>
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:id="#+id/vonal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#FFD700" />
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/vonal2"
android:background="#FFD700"/>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="300dp"
tools:context=".MainActivity"
android:id="#+id/relativemaplayout">
<fragment
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
class="com.google.android.gms.maps.MapFragment" />
<ImageView
android:id="#+id/transparent_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="onClick"
android:background="?android:selectableItemBackground"/>
</RelativeLayout>
</RelativeLayout>
View v = inflater.inflate(R.layout.activity_service_info,parent, false);
mScrollView = (ScrollView) v.findViewById(R.id.scrollView);
transparentImageView = (ImageView) v.findViewById(R.id.transparent_image);
mScrollView.requestDisallowInterceptTouchEvent(true);
transparentImageView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
Log.d("action","down");
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
mScrollView.requestDisallowInterceptTouchEvent(true);
Log.d("action","down");
return false;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
mScrollView.requestDisallowInterceptTouchEvent(false);
Log.d("action","up");
return true;
case MotionEvent.ACTION_MOVE:
mScrollView.requestDisallowInterceptTouchEvent(true);
Log.d("action","move");
return false;
default:
return true;
}
}
});
transparentImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getActivity(), "anyád", Toast.LENGTH_SHORT).show();
}
});
I don't know why but the transparent ImageView does not respond for click. What should I do to make the ImageView react for the click? I have tried some other way to make the ScrollView work but non of them worked and this solution looks pretty good.
I have an Activity which have navigation drawer that works perfectly but behind the drawer ScrollView doesn't work.
Here is my xml code,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="4dp"
tools:context="com.bala.beautytipstamil.Content">
<WebView
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/include"
android:layout_below="#+id/txtTitle">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imgContent"
android:layout_width="match_parent"
android:layout_height="150dp" />
<WebView
android:id="#+id/txtContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
<include
android:id="#+id/include"
layout="#layout/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#ffeeeeee" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
Please help!
Put your ScrollView inside DrawerLayout like below code. just copy and paste it.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="4dp"
tools:context="com.bala.beautytipstamil.Content">
<WebView
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/include"
android:layout_below="#+id/txtTitle">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imgContent"
android:layout_width="match_parent"
android:layout_height="150dp" />
<WebView
android:id="#+id/txtContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
<include
android:id="#+id/include"
layout="#layout/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<ListView
android:id="#+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#ffeeeeee" />
</android.support.v4.widget.DrawerLayout>
public class VerticalScrollview extends ScrollView {
public VerticalScrollview(Context context) {
super(context);
}
public VerticalScrollview(Context context, AttributeSet attrs) {
super(context, attrs);
}
public VerticalScrollview(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:
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_MOVE:
return false; // redirect MotionEvents to ourself
case MotionEvent.ACTION_CANCEL:
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_UP:
return false;
default: break;
}
return false;
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
super.onTouchEvent(ev);
return true;
}
}
I am kinda new in android and got such a problem, I am trying to use ExpandableHeightGridView for gridview inside scrollview, but layout doesn't render, some advice please.
It always gives me this error:
Exception raised during rendering: ScrollView can host only one direct child
ExpandableHeightGridView.class:
public class ExpandableHeightGridView extends GridView {
boolean expanded = false;
public ExpandableHeightGridView(Context context)
{
super(context);
}
public ExpandableHeightGridView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public ExpandableHeightGridView(Context context, AttributeSet attrs,
int defStyle)
{
super(context, attrs, defStyle);
}
public boolean isExpanded()
{
return expanded;
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
// HACK! TAKE THAT ANDROID!
if (isExpanded())
{
// Calculate entire height by providing a very large height hint.
// View.MEASURED_SIZE_MASK represents the largest height possible.
int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
else
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded)
{
this.expanded = expanded;
} }
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#fed70d"
android:orientation="horizontal">
<ImageView
android:id="#+id/iconBack"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:paddingBottom="16dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="16dp"
android:src="#drawable/icon_back_white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="Wishlist"
android:textColor="#ac920d"
android:textSize="24sp" />
<LinearLayout
android:id="#+id/myCart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|right"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/addedInCart"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_gravity="center|right"
android:src="#drawable/icon_menu_cart" />
<TextView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginTop="5dp"
android:background="#drawable/icon_mycart_count"
android:gravity="center_horizontal|center"
android:text="2"
android:textColor="#ffffff"
android:textSize="10dp" />
</LinearLayout>
<TextView
android:id="#+id/myMoneyInMyPocket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:layout_marginRight="10dp"
android:text="2000$"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ad8c22" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#fed70d"
android:orientation="horizontal"
android:weightSum="5.0">
<LinearLayout
android:id="#+id/menuItemStores"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical"
android:paddingTop="8dp">
<ImageView
android:id="#+id/menuIconStores"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_gravity="center"
android:src="#drawable/icon_menu_logo" />
<TextView
android:id="#+id/menuTextStores"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Stores"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/menuItemInfo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical"
android:paddingTop="8dp">
<ImageView
android:id="#+id/menuIconInfo"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_gravity="center"
android:src="#drawable/icon_menu_info" />
<TextView
android:id="#+id/menuTextInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Info"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:background="#drawable/selected_menu_background"
android:orientation="vertical"
android:paddingTop="8dp">
<ImageView
android:id="#+id/menuIconWishlist"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_gravity="center"
android:src="#drawable/icon_wishlist" />
<TextView
android:id="#+id/menuTextWishlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Wishlist"
android:textColor="#ffffff"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/menuItemAccount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical"
android:paddingTop="8dp">
<ImageView
android:id="#+id/menuIconAccount"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_gravity="center"
android:src="#drawable/icon_menu_account" />
<TextView
android:id="#+id/menuTextAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Account"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/menuItemCart"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical"
android:paddingTop="8dp">
<ImageView
android:id="#+id/menuIconCart"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_gravity="center"
android:src="#drawable/icon_menu_cart" />
<TextView
android:id="#+id/menuTextCart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Cart"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/dropShadow"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#drawable/drop_shadow"
android:cacheColorHint="#f1e7dd"
android:paddingTop="8dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<com.example.utils.ExpandableHeightGridView
android:id="#+id/wishListGridView"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:columnWidth="80dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:isScrollContainer="false"
android:numColumns="2"
android:paddingBottom="#dimen/activity_horizontal_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
This problem is discussed here.
Try adding one more LinearLayout inside your ScrollView as a direct child and put all other layouts/controls inside of the new LinearLayout.