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.
Related
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 have an linear layout in my application,In that i am using one root layout(invitation_single) and one nested layout(hidden).when i am onclick root layout at run time the nested layout visible(it contains"yes,no,maybe" buttons)successfully.Now my need is if i have similar layout values(consider event 2) immediately below the previous layout values(consider event 1),when i am on click "event 2" i need to hide nested layout of "event 1"(atpresent when i am click button the nested layout gone)automatically.how can i achieve this..here is my layout code,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/invitation_single"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="?android:dividerVertical"
android:dividerPadding="5dp"
android:showDividers="middle"
tools:context=".MainActivity">
<ImageButton
android:id="#+id/image"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_action_event" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="true"
android:orientation="vertical">
<TextView
android:id="#+id/invitation_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:paddingTop="3dp"
android:textColor="#color/black"
android:textSize="18sp" />
<TextView
android:id="#+id/invitation_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:textColor="#color/black"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/hidden"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginLeft="-270dp"
android:layout_marginTop="60dp"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:paddingTop="1dp"
android:visibility="gone"
android:weightSum="3">
<Button
android:id="#+id/yesbutton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="7dp"
android:layout_weight="1"
android:background="#color/blue"
android:text="Yes"
android:textColor="#color/black"></Button>
<Button
android:id="#+id/nobutton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="25dp"
android:layout_weight="1"
android:background="#color/blue"
android:text="No"
android:textColor="#color/black"></Button>
<Button
android:id="#+id/buttonmaybe"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#color/blue"
android:text="Maybe"
android:textColor="#color/black"></Button>
</LinearLayout>
</LinearLayout>
my programming code is below,
final LinearLayout first = (LinearLayout) convertView.findViewById(R.id.invitation_single);
final LinearLayout second = (LinearLayout) convertView.findViewById(R.id.hidden);
first.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.invitation_single:
second.setVisibility(View.VISIBLE);
break;
}
}
});
is this what you're looking for?
first.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.invitation_single:
second.setVisibility(second.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
break;
}
}
});
I am working on MultiDirectionSlidingDrawer motion events. I have a problem on Action_Move.
I am unable to set Visible or Gone layouts on Action_Move.
I have handle with two buttons. When I drag click on first button it should show the first view also the same for second button.
slidingDrawer.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
int width = getActivity().getWindowManager()
.getDefaultDisplay().getWidth();
width = width / 2;
if (event.getX() < width) {
System.out.println("Visible view 1");
view1.setVisibility(View.VISIBLE);
view2.setVisibility(View.GONE);
}else{
System.out.println("Visible view 2");
view1.setVisibility(View.GONE);
view2.setVisibility(View.VISIBLE);
}
}
}
}
My xml view :
<com.myproject.widget.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/com.lesmobilizers.chronoresto"
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:content="#+id/content"
app:direction="topToBottom"
app:handle="#+id/handle" >
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/gray"
android:orientation="vertical"
android:visibility="gone" />
<LinearLayout
android:id="#+id/view2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:orientation="vertical" />
</LinearLayout>
<LinearLayout
android:id="#+id/handle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/menufiche_content"
android:layout_marginTop="-24dp"
android:background="#drawable/btn_restaurant_pannel_switch_close"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:id="#+id/lt_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<com.myproject.widget.FontCustomTextView
android:id="#+id/menutext"
style="#style/font_button_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:drawableRight="#drawable/img_arrow_down"
android:text="Menu "
android:textColor="#color/gray"
android:textSize="17sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/lt_fiche"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<com.myproject.widget.FontCustomTextView
android:id="#+id/fichetxt"
style="#style/font_button_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:drawableRight="#drawable/img_arrow_down"
android:text="Fiche "
android:textColor="#color/gray"
android:textSize="17sp" />
</LinearLayout>
</LinearLayout>
</com.myproject.widget.MultiDirectionSlidingDrawer>
System.out are working fine. But the thing is view1, view2 Visibilities are not working as my code says.
I hope you are getting my problem. I need your suggestion about Action_Move.
I have a parent vertical linear layout. in that i have 10 vertical linear layouts. i wan to drag and drop with those 10 vertical layout like drag and drop listview am new to android please help me.
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/center"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FF8989"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dragtext" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag quick" />
</LinearLayout>
<LinearLayout
android:id="#+id/l2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFCC00"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag soon" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag upon" />
</LinearLayout>
<LinearLayout
android:id="#+id/l3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#fff"
android:orientation="vertical" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag me" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Draging" />
</LinearLayout>
<LinearLayout
android:id="#+id/l4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FF8989"
android:orientation="vertical" >
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag out"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag in"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:id="#+id/l5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFCC00"
android:orientation="vertical" >
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Draged"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_1"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:id="#+id/l6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_2"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_3"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:id="#+id/l7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FF8989"
android:orientation="vertical" >
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_4"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_5"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:id="#+id/l8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFCC00"
android:orientation="vertical" >
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_6"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_7"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:id="#+id/l9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_8"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_9"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:id="#+id/l10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FF8989"
android:orientation="vertical" >
<TextView
android:id="#+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_10"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag_11"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
//java file
here am implement onDragListener and onTouchListener and i set setOnDragListener to every layout
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(null, shadowBuilder, view, 0);
view.setVisibility(View.INVISIBLE);
return true;
} else {
return false;
}
}
#Override
public boolean onDrag(View layoutview, DragEvent dragevent) {
int action = dragevent.getAction();
switch (action) {
case DragEvent.ACTION_DRAG_STARTED:
Log.d(LOGCAT, "Drag event started");
break;
case DragEvent.ACTION_DRAG_ENTERED:
Log.d(LOGCAT, "Drag event entered into " + layoutview.toString());
break;
case DragEvent.ACTION_DRAG_EXITED:
Log.d(LOGCAT, "Drag event exited from " + layoutview.toString());
break;
case DragEvent.ACTION_DRAG_LOCATION:
break;
case DragEvent.ACTION_DROP:
Log.d(LOGCAT, "Dropped");
LinearLayout dragged = (LinearLayout) dragevent.getLocalState();
LinearLayout target = (LinearLayout) layoutview;
int t = target.getNextFocusUpId();
int d = target.getNextFocusDownId();
View view = (View) dragevent.getLocalState();
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
target .addView(view);
view.setVisibility(View.VISIBLE);
break;
case DragEvent.ACTION_DRAG_ENDED:
Log.d(LOGCAT, "Drag ended");
break;
default:
break;
}
return true;
}
But it doesn't work when dragout whole layout(parent layout) are drag and invisible. am new and am struggling please help me.
I have a ViewPager. In each pager, it display a listview. Each row in the Listview contains a HorizontalScrollView element. Here is the code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white" >
<LinearLayout
android:id="#+id/survey_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/store_name"/>
<TextView
android:id="#+id/txt_store_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"/>
</LinearLayout>
<HorizontalScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_below="#id/survey_header"
android:scrollbars="none">
<TableLayout
android:id="#+id/survey_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/survey_table_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txt_status"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#color/red_text"/>
<TextView
android:id="#+id/txt_product"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#color/red_text"/>
<TextView
android:id="#+id/txt_stock"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#color/red_text"/>
</TableRow>
<TableRow
android:id="#+id/menu_table_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#color/red_text"
android:text="#string/survey_status"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#color/red_text"
android:text="#string/product_info"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#color/red_text"
android:text="#string/stock_count"/>
</TableRow>
</TableLayout>
</HorizontalScrollView>
</RelativeLayout>
Everytime I try to scroll the horizontal Scroll View, the ViewPager receives touch event first and change the page.
How can I disable the changing page of ViewPager when I touch Horizontal Scorll View.
Thanks in advance.
HorizontalScrollView scrollView=(HorizontalScrollView)findViewById(R.id.scrollView);
scrollView.setOnTouchListener(new View.OnTouchListener() {
float rawX;
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
scrollView.getParent().requestDisallowInterceptTouchEvent(true);
rawX = event.getRawX();
return false;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
scrollView.getParent().requestDisallowInterceptTouchEvent(false);
rawX = 0f;
return false;
case MotionEvent.ACTION_MOVE:
if (Math.abs(rawX - event.getRawX()) > ViewConfiguration.get(getActivity()).getScaledTouchSlop())
scrollView.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return false;
}
});