andriod-设置ScrollView手指滑动事件时ScrollView界面不动

问题描述

设置ScrollView手指滑动事件时ScrollView界面不动
java代码
package com.example.edit_date;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.GestureDetector.OnGestureListener;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;

public class MainActivity extends Activity implements OnTouchListener
OnGestureListener {
Button bt_edit_date;
private GestureDetector myGestureDetector;
private LinearLayout linely_top;
private ScrollView sl_date;

@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    requestWindowFeature(Window.FEATURE_NO_TITLE);    setContentView(R.layout.person_infor);    bt_edit_date = (Button) this.findViewById(R.id.bt_edit_date);    linely_top = (LinearLayout) findViewById(R.id.linely_top);    sl_date = (ScrollView) findViewById(R.id.sl_date);    sl_date.setOnTouchListener(this);    myGestureDetector.setIsLongpressEnabled(true);    bt_edit_date.setOnClickListener(new OnClickListener() {        @Override        public void onClick(View v) {            // TODO Auto-generated method stub            Intent intent = new Intent(MainActivity.this Edit_date.class);            MainActivity.this.startActivity(intent);        }    });}public MainActivity() {    myGestureDetector = new GestureDetector(this);}@Overridepublic boolean onTouch(View v MotionEvent event) {    // TODO Auto-generated method stub    return myGestureDetector.onTouchEvent(event);}@Overridepublic boolean onDown(MotionEvent arg0) {    // TODO Auto-generated method stub    return true;}@Overridepublic boolean onFling(MotionEvent e1 MotionEvent e2 float arg2        float arg3) {    // TODO Auto-generated method stub    System.out.println(""++--onFling"");    if (e1.getX() - e2.getX() >= -20) {        linely_top.setBackgroundColor(Color.rgb(157 207 251));        linely_top.getBackground().setAlpha(0);    } else if (e1.getX() - e2.getX() <= 20) {        linely_top.getBackground().setAlpha(200);    }    return true;}@Overridepublic void onLongPress(MotionEvent arg0) {    // TODO Auto-generated method stub}@Overridepublic boolean onScroll(MotionEvent e1 MotionEvent e2 float arg2        float arg3) {    // TODO Auto-generated method stub    System.out.println(""++--onScroll"");    if (e1.getX() - e2.getX() >= -20) {        linely_top.setBackgroundColor(Color.rgb(157 207 251));        linely_top.getBackground().setAlpha(0);    } else if (e1.getX() - e2.getX() <= 20) {        linely_top.getBackground().setAlpha(200);    }    return true;}@Overridepublic void onShowPress(MotionEvent arg0) {    // TODO Auto-generated method stub}@Overridepublic boolean onSingleTapUp(MotionEvent arg0) {    // TODO Auto-generated method stub    return true;}

}

xml代码
<?xml version=""1.0"" encoding=""utf-8""?>
android:id=""@+id/rl_main""
android:layout_width=""match_parent""
android:layout_height=""match_parent""
android:orientation=""vertical"" >

<ScrollView    android:id=""@+id/sl_date""    android:layout_width=""match_parent""    android:layout_height=""wrap_content""            >    <LinearLayout        android:id=""@+id/rl_scrol_date""        android:layout_width=""match_parent""        android:layout_height=""wrap_content""        android:orientation=""vertical"" >        <ImageView            android:id=""@+id/image_line""            android:layout_width=""fill_parent""            android:layout_height=""wrap_content""            android:src=""@drawable/text"" />        <com.example.edit_date.CircleImageView            xmlns:app=""http://schemas.android.com/apk/res-auto""            android:id=""@+id/id_main_actionbar_photo""            android:layout_width=""70dp""            android:layout_height=""70dp""            android:layout_marginLeft=""10dp""            android:layout_marginTop=""-35dp""            android:src=""@drawable/head"" />        <LinearLayout            android:layout_width=""fill_parent""            android:layout_height=""wrap_content""            android:layout_marginTop=""-40dp""            android:orientation=""horizontal"" >            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""6.5"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""7.5""                android:text=""失却""                android:textColor=""#9f9d9d""                android:textSize=""20sp"" />        </LinearLayout>        <LinearLayout            android:layout_width=""fill_parent""            android:layout_height=""wrap_content""            android:orientation=""horizontal"" >            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""5"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""9""                android:text=""男 20岁 安徽 黄山""                android:textColor=""#9f9d9d""                android:textSize=""14sp"" />        </LinearLayout>        <ImageView            android:layout_width=""fill_parent""            android:layout_height=""wrap_content""            android:layout_marginTop=""10dp""            android:src=""@drawable/line"" />        <LinearLayout            android:layout_width=""match_parent""            android:layout_height=""wrap_content""            android:orientation=""horizontal"" >            <TextView                android:id=""@+id/tv_phone_number""                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""4""                android:paddingBottom=""10dp""                android:paddingLeft=""10dp""                android:paddingTop=""10dp""                android:text=""手机号码""                android:textColor=""#9f9d9d""                android:textSize=""18sp"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""1"" />            <TextView                android:id=""@+id/tv_usernumber""                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""6""                android:paddingBottom=""10dp""                android:paddingTop=""10dp""                android:text=""1397243180""                android:textSize=""18sp"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""1"" />            <ImageView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_gravity=""center_vertical""                android:layout_weight=""2""                android:paddingBottom=""10dp""                android:paddingTop=""10dp""                android:src=""@drawable/trun"" />        </LinearLayout>        <ImageView            android:layout_width=""fill_parent""            android:layout_height=""wrap_content""            android:src=""@drawable/line"" />        <LinearLayout            android:layout_width=""match_parent""            android:layout_height=""wrap_content""            android:orientation=""horizontal"" >            <TextView                android:id=""@+id/tv_two_infor""                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""4""                android:paddingBottom=""10dp""                android:paddingLeft=""10dp""                android:paddingTop=""10dp""                android:text=""二手信息""                android:textColor=""#9f9d9d""                android:textSize=""18sp"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""1"" />            <TextView                android:id=""@+id/tv_two_infordate""                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""6""                android:paddingBottom=""10dp""                android:paddingLeft=""10dp""                android:paddingTop=""10dp""                android:textColor=""#9f9d9d""                android:textSize=""18sp"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""1"" />            <ImageView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_gravity=""center""                android:layout_weight=""2""                android:paddingBottom=""10dp""                android:paddingTop=""10dp""                android:src=""@drawable/trun"" />        </LinearLayout>        <ImageView            android:layout_width=""fill_parent""            android:layout_height=""wrap_content""            android:src=""@drawable/line"" />        <LinearLayout            android:layout_width=""match_parent""            android:layout_height=""wrap_content""            android:orientation=""horizontal"" >            <TextView                android:id=""@+id/tv_sign""                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""4""                android:paddingBottom=""10dp""                android:paddingLeft=""10dp""                android:paddingTop=""10dp""                android:text=""个性签名""                android:textColor=""#9f9d9d""                android:textSize=""18sp"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""1"" />            <TextView                android:id=""@+id/tv_signvalue""                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""6""                android:paddingBottom=""10dp""                android:paddingTop=""10dp""                android:text=""没有实力的愤怒没有任何意义""                android:textSize=""18sp"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""1"" />            <ImageView                android:layout_width=""wrap_content""                android:layout_height=""wrap_content""                android:layout_gravity=""center_vertical""                android:layout_weight=""2""                android:src=""@drawable/trun"" />        </LinearLayout>        <ImageView            android:layout_width=""fill_parent""            android:layout_height=""wrap_content""            android:src=""@drawable/line"" />        <LinearLayout            android:layout_width=""match_parent""            android:layout_height=""wrap_content""            android:orientation=""horizontal"" >            <TextView                android:id=""@+id/tv_space""                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""4""                android:paddingLeft=""10dp""                android:text=""我的微店""                android:textColor=""#9f9d9d""                android:textSize=""18sp"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""1"" />            <TextView                android:id=""@+id/tv_space""                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""6""                android:paddingBottom=""10dp""                android:paddingTop=""10dp""                android:text="" ""                android:textSize=""18sp"" />            <TextView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""1"" />            <ImageView                android:layout_width=""1dp""                android:layout_height=""wrap_content""                android:layout_weight=""2""                android:paddingBottom=""10dp""                android:paddingTop=""10dp""                android:src=""@drawable/trun"" />        </LinearLayout>        <ImageView            android:layout_width=""fill_parent""            android:layout_height=""wrap_content""            android:src=""@drawable/line""             android:layout_marginBottom=""100dp""/>    </LinearLayout></ScrollView><LinearLayout    android:id=""@+id/linely_top""    android:layout_width=""match_parent""    android:layout_height=""40dp""    android:layout_alignParentTop=""true"" >    <ImageView        android:layout_width=""wrap_content""        android:layout_height=""20dp""        android:layout_marginLeft=""5dp""        android:layout_marginTop=""5dp""        android:src=""@drawable/back"" /></LinearLayout><LinearLayout    android:layout_width=""match_parent""    android:layout_height=""wrap_content""    android:layout_alignParentBottom=""true""    android:orientation=""horizontal"" >    <Button        android:id=""@+id/bt_edit_date""        android:layout_width=""match_parent""        android:layout_height=""wrap_content""        android:background=""#9DCFFB""        android:paddingBottom=""5dp""        android:paddingTop=""5dp""        android:text=""编辑资料""        android:textColor=""#5CC7E8""        android:textSize=""24sp"" /></LinearLayout>
时间: 2024-09-17 04:51:52

andriod-设置ScrollView手指滑动事件时ScrollView界面不动的相关文章

Android中ScrollView实现滑动距离监听器的方法_Android

前言 众所周知ScrollView是我们经常使用的一个UI控件,也许你在使用ScrollView的过程中会发现,当你想监听ScrollView滑动的距离时却没有合适的监听器!当然在API 23中有setOnScrollChangeListener(View.OnScrollChangeListener l)可以使用,但是并不兼容低版本的API.那怎么办呢?只好重写ScrollView来实现对滑动距离的监听了. 话不多说,直接上代码: public class MyScrollView exten

Android onTouch、OnLongClick、onClick及ScrollView滑动事件冲突

 最近要实现一个长按录音,松开手指结束录音的功能,在项目中,弄来弄去绕晕了,写个demo来梳理下.顺便研究下android事件调用机制.   先上效果界面: 布局:     [html] view plaincopy <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"       xmlns:tools="http://schemas.android.com/tools&q

Android中实现监听ScrollView滑动事件_Android

时候我们需要监听ScroView的滑动情况,比如滑动了多少距离,是否滑到布局的顶部或者底部.可惜的是SDK并没有相应的方法,不过倒是提供了一个 复制代码 代码如下: protected void onScrollChanged(int x, int y, int oldx, int oldy)  方法,显然这个方法是不能被外界调用的,因此就需要把它暴露出去,方便使用.解决方式就是写一个接口, 复制代码 代码如下: package com.example.demo1;    public inte

Android中实现监听ScrollView滑动事件

时候我们需要监听ScroView的滑动情况,比如滑动了多少距离,是否滑到布局的顶部或者底部.可惜的是SDK并没有相应的方法,不过倒是提供了一个 复制代码 代码如下: protected void onScrollChanged(int x, int y, int oldx, int oldy) 方法,显然这个方法是不能被外界调用的,因此就需要把它暴露出去,方便使用.解决方式就是写一个接口, 复制代码 代码如下: package com.example.demo1;    public inter

浅谈Android实践之ScrollView中滑动冲突处理解决方案_Android

1. 前言  在Android开发中,如果是一些简单的布局,都很容易搞定,但是一旦涉及到复杂的页面,特别是为了兼容小屏手机而使用了ScrollView以后,就会出现很多点击事件的冲突,最经典的就是ScrollView中嵌套了ListView.我想大部分刚开始接触Android的同学们都踩到过这个坑,这一篇文章就从最近做的一个项目讲起,然后在过程中提供一些解决冲突的思路. 2. 项目起始 项目有一个页面,涉及到了ViewPager,MapView,ListView,也就是说在一个页面中,会有这三个

浅谈Android实践之ScrollView中滑动冲突处理解决方案

1. 前言 在Android开发中,如果是一些简单的布局,都很容易搞定,但是一旦涉及到复杂的页面,特别是为了兼容小屏手机而使用了ScrollView以后,就会出现很多点击事件的冲突,最经典的就是ScrollView中嵌套了ListView.我想大部分刚开始接触Android的同学们都踩到过这个坑,这一篇文章就从最近做的一个项目讲起,然后在过程中提供一些解决冲突的思路. 2. 项目起始 项目有一个页面,涉及到了ViewPager,MapView,ListView,也就是说在一个页面中,会有这三个V

slide menu-android 实现滑动菜单时遇到滑动事件不能触发的问题

问题描述 android 实现滑动菜单时遇到滑动事件不能触发的问题 界面里只有个EditText和几个按钮,但是向右滑动时,滑动事件不能发生,直接变成编辑文本框,改成TextView就可以,这样的问题怎么解决? 解决方案 不出意外应该是EditText默认就获取了焦点,导致滑动事件不能响应.比较好的做法是让父控件获取焦点,如设置LinearLayout的focusable 和focusableInTouchMode属性为true 解决方案二: 这种问题还是要把源代码贴上来才能看出来.

scrollview-如何在extends了Activity的类里判断ScrollView的滑动高度..

问题描述 如何在extends了Activity的类里判断ScrollView的滑动高度.. 想要的效果图: 无滑动时立即购买的layout在商品大图下边,当滑动使大图消失在屏幕顶端时,这个layout固定在屏幕下方.如图: 解决方案 它的高度就是你屏幕的高度,它里面内容的高度是不固定的,你可以通过手势动作得到scrollview的滚动距离及是否滚到结束,参考http://www.2cto.com/kf/201401/273264.html

android 滑动冲突-Android ScrollView 中 TextView 多行显示问题,textview不能滑动

问题描述 Android ScrollView 中 TextView 多行显示问题,textview不能滑动 textview的多行滚动变成不能滑动了,被scrollview的滑动给拿去了. 至于 百度说的改成 wrap_content也是不行的. 解决方案 Android textview 多行显示Android textview显示多行android textview 多行之后显示省略号 解决方案二: android:layout_height="wrap_content" 给个高