Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.testnhat;
- 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.view.LayoutInflater;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.animation.TranslateAnimation;
- import android.widget.FrameLayout;
- import android.widget.LinearLayout;
- import android.widget.RelativeLayout;
- import android.widget.ScrollView;
- import android.widget.TextView;
- import com.example.testnhat.R;
- public class MainActivity extends AppCompatActivity {
- LinearLayout scrTest;
- TextView txtHandler;
- LinearLayout lnlTest;
- int y, h,saveH;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- init();
- }
- void init() {
- scrTest = (LinearLayout) 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) {
- // e(event.getAction());
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
- 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 = (int) lnlTest.getY();
- saveH=scrTest.getHeight();
- }
- return true;
- } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
- if (y != -1) {
- // RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) scrTest.getLayoutParams();
- int subtract = (int) event.getRawY() - y;
- // lp.height = h + subtract;
- // scrTest.setLayoutParams(lp);
- // scrTest.fullScroll(ScrollView.FOCUS_DOWN);
- lnlTest.setY(h+subtract);
- LinearLayout.LayoutParams lp= (LinearLayout.LayoutParams) scrTest.getLayoutParams();
- lp.height=saveH+subtract;
- scrTest.setLayoutParams(lp);
- return true;
- }
- } else if (event.getAction() == MotionEvent.ACTION_UP) {
- y = -1;
- return true;
- }
- return true;
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment