Get the height of dynamically added LinearLayouts in Android - android

I am working in an android application and I am adding a Linear Layout dynamically in my Scollview. Now I want to get the height of each Linear Layout added dynamically . Below is my code and Xml.
LinearLayout layout = (LinearLayout) findViewById(R.id.subscrollLinearLayout);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
List<String> mSempLog = new ArrayList<String>();
mSempLog.add("TEST1");
mSempLog.add("TEST2");
mSempLog.add("TEST3");
mSempLog.add("TEST4");
mSempLog.add("TEST5");
mSempLog.add("TEST6");
mSempLog.add("TEST7");
mSempLog.add("TEST8");
for (int i = 0; i < mSempLog.size(); i++) {
LinearLayout service_row = (LinearLayout) inflater.inflate(
R.layout.tesffff, null);
TextView dd = ((TextView) service_row.findViewById(R.id.test1));
dd.setText(mSempLog.get(i));
dd.setTag(i);
((TextView) service_row.findViewById(R.id.test2)).setText(mSempLog
.get(i));
layout.addView(service_row, i);
}
ScrollView parentScrollView = (ScrollView) findViewById(R.id.parentscroll);
ScrollView childScrollView = (ScrollView) findViewById(R.id.subscroll);
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.subscroll).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
#Override
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;
}
});
}
Xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parentscroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:id="#+id/subscroll"
android:layout_width="match_parent"
android:layout_height="200dp" >
<LinearLayout
android:id="#+id/subscrollLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<TextView
android:id="#+id/test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dfsdfsdf" />
<TextView
android:id="#+id/test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dfsdfsdf" />
<TextView
android:id="#+id/test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dfsdfsdf" />
<TextView
android:id="#+id/test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dfsdfsdf" />
<TextView
android:id="#+id/test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dfsdfsdf" />
<TextView
android:id="#+id/test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dfsdfsdf" />
<TextView
android:id="#+id/test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dfsdfsdf" />
<TextView
android:id="#+id/test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dfsdfsdf" />
<TextView
android:id="#+id/test1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dfsdfsdf" />
</LinearLayout>
</ScrollView>
Row 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="match_parent"
android:orientation="horizontal"
android:padding="15dp"
android:weightSum="2" >
<TextView
android:id="#+id/test1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:clickable="true"
android:onClick="onTest1"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/test2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:gravity="center"
android:onClick="onTest2"
android:textColor="#android:color/black" />
</LinearLayout>

This worked for me
MyListViewObj.post(new Runnable(){
public void run(){
int height = MyListViewObj.getHeight();
}
});

Actually you can get width by few ways.
case 1: yourView.getHeight() (only when the view was already drawn)
case 2: yourView.getLayoutParams().height (depends on LayoutParams)
case 3: http://www.limbaniandroid.com/2014/10/viewtreeobserver-how-to-get-layout.html
case 4: If you have custom layout then you can get height in onMeasure (http://developer.android.com/reference/android/view/View.html#onMeasure(int,
int))

Related

Reverse layouts inside RelativeLayout programmatically

I have one relativeLayout and three view's inside RelativeLayout. There views are place on each other.
<RelativeLayout
android:id="#+id/includelayoutgroup"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/transparentColorView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<include
layout="#layout/transfer_keyboard_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/finalRequestView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible">
<include
layout="#layout/fragment_transfer_new_version_container_child"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</RelativeLayout>
Is it a possible to reverse position my view's? I mean,in my code last Layout is finalRequestView and in button click i would to my last view in first position,and other view's place on my view,
How i can solve this problem?
I try to reverse layout by following demo & it works as you want, please take a look
ReverseLayout.java
public class ReverseLayout extends AppCompatActivity {
LinearLayout llRoot;
Button btReverseLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reverse_layout);
llRoot = (LinearLayout) findViewById(R.id.llRoot);
btReverseLayout = (Button) findViewById(R.id.btReverseLayout);
btReverseLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ArrayList<View> alViews = new ArrayList<View>();
for (int i = llRoot.getChildCount() - 1; i >= 0; i--) {
View view = llRoot.getChildAt(i);
llRoot.removeViewAt(i);
alViews.add(view);
}
for (int j = 0; j < alViews.size(); j++) {
llRoot.addView(alViews.get(j));
}
}
});
}
}
reverse_layout.xml layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tosc185.testproject.Activity6">
<LinearLayout
android:id="#+id/llRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/btReverseLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Reverse Layout" />
</RelativeLayout>

How to disable Scrollview

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......!!!

View Visibility is not working on ACTION_MOVE

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.

Android: views in container still clickable after container view set to View.GONE

I have a LinearLayout that is a view in a FrameLayout. This LinearLayout sits on top in the frame.
Within this LinearLayout, there are some TextViews that are clickable. When I set the LinearLayout to View.GONE, everything goes away as expected except the TextViews are still clickable.
Why is this? And how do I avoid it other than setting all the clickable TextViews to View.GONE?
XML
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<LinearLayout
android:id="#+id/match_settings_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#40c0a9"
android:visibility="gone"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textSize="20sp"
android:textColor="#fff"
android:text="#string/lbl_age" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontBoldTextView
android:id="#+id/age_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/white_rounded_bg"
android:padding="6dp"
android:textSize="20sp"
android:textColor="#0099cb"
android:text="18 to 99" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textSize="20sp"
android:textColor="#fff"
android:text="#string/lbl_location" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontBoldTextView
android:id="#+id/location_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/white_rounded_bg"
android:padding="6dp"
android:textSize="20sp"
android:textColor="#0099cb"
android:text="Any Distance" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
Activity
// Handles expanding match settings window
final ToggleButton btnShowMatchSettings = (ToggleButton) findViewById(R.id.btn_show_match_settings);
btnShowMatchSettings.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
LinearLayout container = (LinearLayout) findViewById(R.id.match_settings_container);
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
btnShowMatchSettings.setBackgroundResource(R.drawable.ico_menu_open);
container.setAnimation(AnimationUtils.loadAnimation(DashboardActivity.this, R.anim.slide_down));
container.setVisibility(View.VISIBLE);
ageSetting = (CustomFontBoldTextView) findViewById(R.id.age_setting);
ageSetting.setVisibility(View.VISIBLE);
ageSetting.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
new AgePickerDialog().show(getFragmentManager(), "agePicker");
}
});
locationSetting = (CustomFontBoldTextView) findViewById(R.id.location_setting);
locationSetting.setVisibility(View.VISIBLE);
locationSetting.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
new LocationPickerDialog().show(getFragmentManager(), "locationPicker");
}
});
}
else {
btnShowMatchSettings.setBackgroundResource(R.drawable.ico_menu);
container.setAnimation(AnimationUtils.loadAnimation(DashboardActivity.this, R.anim.slide_up));
container.setVisibility(View.GONE);
ageSetting.setVisibility(View.GONE);
locationSetting.setVisibility(View.GONE);
}
}
});
}
The fact that you change the visibility of a view doesn't mean that they are destroyed.
You should try adding something like this
yourButton.setClickable(false) ;

How to stop scrolling when the Custom view has touchlisteners in android?

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;
}
});
}

Categories

Resources