I am using a progress bar in a matched parent layout in my application. Problem is button in the background is still clickable while the progress bar runs. They should not be clickable, so how do I make them non-clickable. The layout is:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black_with_fifty_percent_alpha"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_tv_progress_bar_bultenler"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
Try set this to this layout:
OnTouchListener listener = new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;//consume the touch event
}
};
yourLayout.setOnTouchListener(listener);
Related
I have ScrollView and inside that a TabLayout. How can I disable the ScrollView from scrolling without effecting on TabLayout scroll?
EDIT:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrollview"
android:background="#color/backgroundView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="none"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/slider_height"
android:background="#drawable/border_light"
>
app:pv_progressStyle="#style/LightInColorCircularProgressView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<com.daimajia.slider.library.SliderLayout
android:id="#+id/main_slider"
android:layout_width="match_parent"
android:layout_height="#dimen/slider_height"
/>
<com.daimajia.slider.library.Indicators.PagerIndicator
android:id="#+id/custom_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/AndroidImageSlider_Corner_Oval"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" />
</RelativeLayout>
.... other stuff
<com.rey.material.widget.TabPageIndicator
style="#style/TabPageIndicator"
android:id="#+id/main_tpi"
android:layout_height="48dp"
android:layout_width="match_parent"
android:paddingLeft="0dp"
android:clipToPadding="true"
app:tpi_mode="scroll"
app:tpi_indicatorColor="#color/colorPrimary"
android:background="#color/overlayView"/>
<adapters.CustomViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/main_vp"
/>
</ScrollView>
I used this and it worked for me :
// Get the ScrollView
final ScrollView myScroll = (ScrollView) findViewById(R.id.display_scrollview);
// Disable Scrolling by setting up an OnTouchListener to do nothing
myScroll.setOnTouchListener( new OnTouchListener(){
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
// Enable Scrolling by removing the OnTouchListner
tvDisplayScroll.setOnTouchListener(null);
happy programming......!!!
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 am trying to display multiple GridView in a LinearLayout and ScrollView but if the content of the first scroll view is more then the first GridView fills the screen and the scroll is not working. here is my current layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/FrameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/owngroup_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/own_groups"
android:textAppearance="?android:attr/textAppearanceLarge" />
<GridView
android:id="#+id/GridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</GridView>
<TextView
android:id="#+id/ingroup_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/in_groups"
android:textAppearance="?android:attr/textAppearanceLarge" />
<GridView
android:id="#+id/inGroups"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</GridView>
</LinearLayout>
</ScrollView>
</FrameLayout>
Change android:layout_width="match_parent" of the GridView and test a value.
Smae action with the LinearLayout.
Example : android:layout_width="400dp"
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event)
{
findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event)
{
// Disallow the touch request for parent scroll on touch of
// child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});`
here chield scroll view can be replace with your gridview
I added a ontouchlistener on linearlayout which include a TextView and a ImageView.When I touched the TextView part it works,and the ImageView doesn't work.I want all the linearlayout can get the touch event.What should I do? My XML is as follows:
<?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="50dip"
android:background="#drawable/graytitle_bj1_black"
android:gravity="center|bottom"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/nav_boutique"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="2dip"
android:clickable="true"
android:focusableInTouchMode="true"
android:descendantFocusability="blocksDescendants">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/description"
android:src="#drawable/btn_jingpin_icon"
android:background="#FFF"
android:focusable="false"
android:clickable="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:text="#string/bottom_jingpin"/>
<View
android:id="#+id/nav_boutique_line"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#F00"/>
</LinearLayout>
<View
android:layout_width="1dip"
android:layout_height="fill_parent"/>
<LinearLayout
android:id="#+id/nav_fenlei"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="2dip"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/description"
android:src="#drawable/icon_fenlei"
android:background="#00000000"
android:focusable="false"
android:clickable="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:text="#string/bottom_fenlei"/>
<View
android:id="#+id/nav_fenlei_line"
android:layout_width="fill_parent"
android:layout_height="2dip"/>
</LinearLayout>
<View
android:layout_width="1dip"
android:layout_height="fill_parent"/>
<LinearLayout
android:id="#+id/nav_dingyue"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="2dip"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/description"
android:src="#drawable/btn_zizhudingyue_icon"
android:background="#00000000"
android:clickable="true"
android:focusable="false"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:text="#string/bottom_dingyue"/>
<View
android:id="#+id/nav_dingyue_line"
android:layout_width="fill_parent"
android:layout_height="2dip"/>
</LinearLayout>
<View
android:layout_width="1dip"
android:layout_height="fill_parent"/>
<LinearLayout
android:id="#+id/nav_sousuo"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="2dip"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/description"
android:src="#drawable/icon_sousuo"
android:background="#00000000"
android:focusable="false"
android:clickable="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:text="#string/bottom_sousuo"/>
<View
android:id="#+id/nav_sousuo_line"
android:layout_width="fill_parent"
android:layout_height="2dip"/>
</LinearLayout>
</LinearLayout>
And this is my code:
dingyueLL.setOnTouchListener(new OnTouchListener()
{
#Override
public boolean onTouch(View v, MotionEvent event)
{
setFlagTrue(Navigation.Dingyue.getPosition());
setBtnLine();
return false;
}
});
Create custom linear layout with onintercepttouchevent.
public class MyLayout extends LinearLayout {
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// do whatever you want with the event
// and return true so that children don't receive it
return true;
}
}
check this thread.
http://developer.android.com/training/gestures/viewgroup.html
adding touch listener for liner layout filled with buttons
What i would try is to explicitly add a touch listener to the image, and see what happend. in this listener, dont call the supper, and return false, so the event will propagate to the next listener, hopefully the layout
dingyueLL.setOnTouchListener(new OnTouchListener()
{
#Override
public boolean onTouch(View v, MotionEvent event)
{
setFlagTrue(Navigation.Dingyue.getPosition());
setBtnLine();
return false;
}
});
THEIMAGE.setOnTouchListener(new OnTouchListener()
{
#Override
public boolean onTouch(View v, MotionEvent event)
{
return false;
}
});
also, put a breakpoint in the ontouch function of the listener of the image, to see if it is getting there
I am dynamically adding an Custom Views to the relative layouts.
In my custom View,I have an Child view which can be dragged left and right.Its all working fine with only one view in the Relative layout.But when there are multiple views ACTION_UP events are not called for the dragging child views. so, I want to stop the scrolling when user touches the Dragging childView.
Main xml:
<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="wrap_content"
tools:context=".MainActivity" >
<com.example.dynamicscroll.ObservableScrollView
android:id="#+id/mainScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<HorizontalScrollView
android:layout_width="wrap_content" android:layout_height="fill_parent">
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</HorizontalScrollView>
</com.example.dynamicscroll.ObservableScrollView>
</RelativeLayout>
inflatedfeedmodebloops.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="wrap_content"
android:background="#ababab"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/transparent"
>
<com.example.dynamicscroll.ConstrainedDragAndDropView
android:id="#+id/dndView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/like_small"
android:id="#+id/dummy"
android:visibility="gone"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="#+id/images">
<!-- left circle -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:id="#+id/half_left">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/like_small"
android:id="#+id/like_image"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#+id/like_image"
android:text="36"
android:textSize="25dp"
android:textColor="#DF013A"
android:id="#+id/likes_count"
/>
</RelativeLayout>
<!-- end of left circle -->
<!-- <ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/img_1"
android:background="#drawable/pinkcircle"
android:id="#+id/full_left"
android:layout_centerVertical="true"
android:visibility="gone"
/>
-->
<!-- right circle -->
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:id="#+id/backbtn"
android:layout_centerInParent="true"/>
<!-- end of right circle -->
<!-- cartoon image -->
<RelativeLayout
android:layout_width="200dp"
android:layout_height="200dp" ----->I want to drag this image,so I want to stop
scrolling when user touches this view.
android:layout_centerHorizontal="true"
android:background="#drawable/img_1"
android:layout_marginTop="20dp"
android:id="#+id/cartoon_image">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/like_small"
android:layout_centerInParent="true"
android:id="#+id/ivheart"
android:visibility="gone"
/>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/play_btn"
android:orientation="horizontal"
android:layout_centerInParent="true"
android:id="#+id/play_btn"
>
</RelativeLayout>
</RelativeLayout>
<!-- end of cartoon image -->
</RelativeLayout>
</com.example.dynamicscroll.ConstrainedDragAndDropView>
</RelativeLayout>
</LinearLayout>
For adding Views to Relative Layout:
for(int i=0;i<al_new.size();i++)
{
Log.e("inflating the bloops ","....................");
final View view= getLayoutInflater().inflate(R.layout.inflatedfeedmodebloops, null);
iv= (ImageView)view.findViewById(R.id.main_img);
ivLike=(ImageView)view.findViewById(R.id.like_image);
txtlikesCount=(TextView)view.findViewById(R.id.likes_count);
loader.DisplayImage(al_new.get(i).replace(" ", "%20"), iv);
ConstrainedDragAndDropView dndView = (ConstrainedDragAndDropView)view.findViewById(R.id.dndView);
dndView.setDragHandle(view.findViewById(R.id.cartoon_image),view.findViewById(R.id.half_left),heart);
dndView.setAllowVerticalDrag(false,ScrollingFeedmode.this);
rl.addView(view);
if (view.findViewById(R.id.cartoon_image)!= null && myscrollview!= null) {
view.findViewById(R.id.cartoon_image).setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
mainScrollView.getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
});
}
}
So,can anyone suggest me how can I stop scrolling when user touches the childview.
Use the following code to stopping parent view scrolling while touching childview
if (childView != null && parentView != null) {
childView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.parent_view).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
});
}