Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.testdemonhat;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.os.Bundle;
- import android.support.annotation.Nullable;
- import android.support.v4.app.Fragment;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.LinearLayout;
- import android.widget.RelativeLayout;
- import android.widget.ScrollView;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- ScrollView scrTest;
- TextView txtHandler;
- LinearLayout lnlTest;
- int y, h;//, scrollY;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- init();
- }
- void init() {
- scrTest = (ScrollView) findViewById(R.id.scrTest);
- txtHandler = (TextView) findViewById(R.id.txtHandler);
- lnlTest = (LinearLayout) findViewById(R.id.lnlTest);
- scrTest.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
- Log.e("Mao", "Mao Bang" + event.getRawX());
- Log.e("Mao", "Mao Bang" + event.getRawY());
- int[] lc = new int[2];
- txtHandler.getLocationOnScreen(lc);
- if (event.getRawX() > lc[0] && event.getRawX() < lc[0] + txtHandler.getWidth() &&
- event.getRawY() > lc[1] && event.getRawY() < lc[1] + txtHandler.getHeight()) {
- y = (int) event.getRawY();
- h = scrTest.getHeight();
- // scrollY = scrTest.getScrollY();
- }
- return true;
- } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
- Log.e("Mao", "Mao Khong Bang");
- if (y != -1) {
- RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) scrTest.getLayoutParams();
- int subtract = (int) event.getRawY() - y;
- lp.height = h + subtract;
- scrTest.setLayoutParams(lp);
- // int sy;
- // if ((subtract < 0))
- // sy = Math.abs(subtract);
- // else
- // sy = scrTest.getScrollY();
- int sy;
- if ((subtract < 0))
- sy = Math.abs(subtract);
- else
- sy = scrTest.getScrollY();
- scrTest.scrollTo(scrTest.getScrollX(), sy);
- scrTest.scrollTo(scrTest.getScrollX(), sy);
- return true;
- }
- } else if (event.getAction() == MotionEvent.ACTION_UP) {
- y = -1;
- return true;
- }
- return false;
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment