View Visibility is not working on ACTION_MOVE - android

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.

Related

Android, setNextFocusDownId not working as expected

I have a layout that as inside of it a LinearLayout that will receive a bunch of dynamic EditText, but the problem is that the AutoCompleteTextView next button doesn't go to the next EditText that is inside of the LinearLayout.
This is the XML
<TabHost
android:id="#+id/DocumentTabHost"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="4dp"
android:layout_marginTop="2dp"
app:layout_constraintBottom_toTopOf="#+id/DocumentBTNFinalize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/DocumentTab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView4"
android:layout_width="203dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:text="#string/general_indentify" />
<AutoCompleteTextView
android:id="#+id/DocumentAutoIdentifier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:layout_toStartOf="#+id/DocumentSearchIden"
android:layout_weight="1"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true" />
<ImageButton
android:id="#+id/DocumentSearchIden"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
app:srcCompat="?android:attr/actionModeWebSearchDrawable" />
<LinearLayout
android:id="#+id/DocumentTab1DynamicLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="55dp"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/DocumentTab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/DocumentTab2Relative"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
And this is the part of the code that I have the focus for the EditText
tempText = new DocEditText(Documents.this);
if (firstButton)
{
_autoComplete.setNextFocusDownId(tempText.getId());
firstButton = false;
}
if (TextUtils.equals(GlobalVars.GeneralConfig.get("editTextType"), "1"))
{
tempText.setRawInputType(Configuration.KEYBOARD_QWERTY);
}
tempText.setSingleLine();
tempText.setSQLCampName(idCampo[1]);
tempText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
tempText.setTypeOfEditText(1);
_cabEditText.add(tempText);
tempLayout.addView(tempText);
The _autocomplete is my AutoCompleteTextView and by setting the setNextFocusDownId(tempText.getId()); should not work ? So when I press next on the soft keyboard to go to it?
Well after some time I did pick on this part of the code and was searching and found another solution for this in StackOverFlow link
Here is the solution for it
if (firstButton)
{
_autoComplete.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT)
{
tempText.requestFocus();
}
return false;
}
});
firstButton = false;
}
So basicly when the enter or next button is pressed on the keyboard it will request focus for the next EditText/AutoCompleteTextView that was created dynamicly

android swapping two views using animation when click on imagebutton

I have seen the questions in the stack over flow, even I tried,
Android Translate Animation like Swapping Two Views
But nothing worked for my scenario, I want to swap swap_above linear layout and swap_below linear layouts when click on swap image button. If possible I would like to apply animation for swap imagebutton also, when the views are being swapped.
Thank you,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/from"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="25dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/swap_above"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/from_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/from_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/seek_thumb_pressed"
android:drawablePadding="5dp"
android:text="BANGALORE"
android:textSize="20dp" />
<TextView
android:id="#+id/from_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=" (BLR)"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="0.5dp"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:background="#FFF" />
<View
android:layout_width="60dp"
android:layout_height="0dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/to"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="25dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/swap_below"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/to_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/to_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/seek_thumb_normal"
android:drawablePadding="5dp"
android:text="Hyderabad"
android:textSize="20dp" />
<TextView
android:id="#+id/to_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=" (HYD)"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="#+id/swap"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical|end"
android:background="?android:attr/selectableItemBackground"
android:src="#drawable/seek_thumb_disabled" />
</FrameLayout>
</LinearLayout>
First - set the below xml attributes for each target view's parent which may be blocking the animation :
android:clipChildren="false"
android:clipToPadding="false"
You need to set this attributes at 3 places in your case.
Read more about clipChildren & clipToPadding here -
http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipChildren
http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipToPadding
If your minSDK >=12
Use this for swap animation :
findViewById(R.id.swap).setOnClickListener(new View.OnClickListener() {
boolean isAnimating;
#Override
public void onClick(View v) {
if(isAnimating)
return;
isAnimating=true;
View v1 = findViewById(R.id.swap_above);
View v2 = findViewById(R.id.swap_below);
float x1, y1, x2, y2;
x1 = getRelativeX(v1);//Use v1.getX() if v1 & v2 have same parent
y1 = getRelativeY(v1);//Use v1.getY() if v1 & v2 have same parent
x2 = getRelativeX(v2);//Use v2.getX() if v1 & v2 have same parent
y2 = getRelativeY(v2);//Use v2.getY() if v1 & v2 have same parent
float x_displacement = (x2-x1);
float y_displacement = (y2-y1);
v1.animate().xBy(x_displacement).yBy(y_displacement);
v2.animate().xBy(-x_displacement).yBy(-y_displacement);
long anim_duration = v1.animate().getDuration();
//Wait till animation is over to set isAnimating to false
//take 10 ms as buffer time to ensure proper functioning
//If you remove this timer & isAnimating variable, the animation will function improperly when user rapidly clicks on swap button
new CountDownTimer(anim_duration + 10, anim_duration + 10) {
#Override
public void onTick(long millisUntilFinished) {
}
#Override
public void onFinish() {
isAnimating=false;
}
}.start();
}
//returns x-pos relative to root layout
private float getRelativeX(View myView) {
if (myView.getParent() == myView.getRootView())
return myView.getX();
else
return myView.getX() + getRelativeX((View) myView.getParent());
}
//returns y-pos relative to root layout
private float getRelativeY(View myView) {
if (myView.getParent() == myView.getRootView())
return myView.getY();
else
return myView.getY() + getRelativeY((View) myView.getParent());
}
});
Read about View Property animator here -
http://developer.android.com/reference/android/view/ViewPropertyAnimator.html
http://developer.android.com/guide/topics/graphics/prop-animation.html
Also, you should try to minimize the number of views in your layout.
Read about layout optimization here -
http://developer.android.com/training/improving-layouts/optimizing-layout.html

Android ListView onScroll Fires Multiple Times

I have two views in my fragment. In the first view, I have a linear layout, which holds some controls and in the second view, I have a listview.
I want the linear layout in the first view to be collapsed / expand when I scroll up / down listview.
I tried to handle scroll up / down events of listview in the OnScrollListener and collapse / expand the listview.
But there is a problem with the onScroll method,i.e, when I scroll the listview, it fires many times when I scroll the listview one time. So expanding and collapsing process of linear layout is going crazy.
Here is - what is happening on the screen.
https://www.youtube.com/watch?v=U7KNwS6JlUk
What am I doing wrong?
What is the best way to handle scrol up / down events of listview and collapse / expand linear layout?
My Layout
<LinearLayout 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="com.training.mehmetyilmaz.mywallet.TransactionsActivity.TransactionsFragment"
android:orientation="vertical">
<LinearLayout
android:id="#+id/transactions_filter_linear_layout"
android:layout_width="match_parent"
android:layout_height="160dp"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/blue">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/account_type_label"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
/>
<RadioGroup
android:id="#+id/transactions_account_type_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:id="#+id/transactions_rd_cash"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/cash"
android:checked="true"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
android:buttonTint="#color/white" />
<RadioButton
android:id="#+id/transactions_rd_bank"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/bank"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
android:buttonTint="#color/white"
/>
</RadioGroup>
</LinearLayout><!-- Money Add Type-->
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/currency_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
/>
<Spinner
android:id="#+id/transactions_spinner_currency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/entry_currency"
android:layout_gravity="right"
android:gravity="right|end"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
style="#style/DropDownColor"
android:background="#drawable/abc_spinner_mtrl_am_alpha"
>
</Spinner>
</LinearLayout><!-- Currency -->
</LinearLayout><!-- First Line-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/cyan_ligth"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
>
</View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/money_type_label"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
/>
<RadioGroup
android:id="#+id/transactions_money_type_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:id="#+id/transactions_rd_add"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/add"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
android:buttonTint="#color/white" />
<RadioButton
android:id="#+id/transactions_rd_sub"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/subtract"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
android:buttonTint="#color/white" />
</RadioGroup>
</LinearLayout><!-- Money Type-->
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/entry_date_label_all_dates"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="#dimen/transactions_filter_text"
android:textColor="#color/white"
/>
<Spinner
android:id="#+id/transactions_spinner_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/entry_date"
android:layout_gravity="right"
android:gravity="right|end"
android:textSize="#dimen/transactions_filter_text"
style="#style/DropDownColor"
android:background="#drawable/abc_spinner_mtrl_am_alpha">
</Spinner>
</LinearLayout><!-- Date -->
</LinearLayout><!-- Second Line -->
</LinearLayout><!-- Filter -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.training.mehmetyilmaz.mywallet.ScrollDetectingListView
android:layout_width="match_parent"
android:layout_height="320dp"
android:id="#+id/transactions_list_view"
></com.training.mehmetyilmaz.mywallet.ScrollDetectingListView>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/transactions_total_textView"
android:text="#string/total"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:textSize="#dimen/abc_text_size_medium_material"
android:background="#color/green"
android:textColor="#color/white"
android:gravity="center"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</LinearLayout>
OnScrollListener
mTransactionListView.setOnScrollListener(new AbsListView.OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
//Log.d("Scroll State", "State : " + scrollState);
}
private int mInitialScroll = 0;
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.d("Scroll", "Called");
int scrolledOffset = mTransactionListView.getVerticalScrollOffset();
if (scrolledOffset != mInitialScroll) {
boolean scrollUp = (scrolledOffset - mInitialScroll) < 0;
if (scrollUp) {
Log.d("Scroll", "Up");
expand(mTransactionsFilterLinearLayout);
} else {
Log.d("Scroll", "Down");
collapse(mTransactionsFilterLinearLayout);
}
mInitialScroll = scrolledOffset;
}
}
});
I think the solution is not possible with the classic ListView of Android SDK.
I found a custom ListView called Android-ObservableScrollView and implemented it in my project and the result is success.
You can find it from here
https://github.com/ksoichiro/Android-ObservableScrollView/
try setting a booolean value like this as global.
boolean flag = true;
then
if (scrollUp) {
if(flag == false){
Log.d("Scroll", "Up");
expand(mTransactionsFilterLinearLayout);
}
flag = true;
} else {
if(flag == true){
Log.d("Scroll", "Down");
collapse(mTransactionsFilterLinearLayout);
}
flag = false;
}

Get the height of dynamically added LinearLayouts in 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))

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