问题描述
- 设置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>