-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3db932c
commit 302c6fe
Showing
12 changed files
with
135 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/aranandroid/customview/ui/ScrollActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.aranandroid.customview.ui | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Activity | ||
import android.os.Bundle | ||
import android.os.PersistableBundle | ||
import android.widget.RadioButton | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.aranandroid.customview.R | ||
import com.aranandroid.customview.squareview.SquareTextView | ||
import kotlinx.android.synthetic.main.activity_square_textview.* | ||
import kotlinx.android.synthetic.main.item_main.* | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.runBlocking | ||
|
||
class ScrollActivity : AppCompatActivity() { | ||
@SuppressLint("WrongViewCast") | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_scroll) | ||
|
||
|
||
|
||
GlobalScope.launch { | ||
repeat(89) { | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
customview/src/main/java/com/aranandroid/customview/scrollview/ScrollLinearLayout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.aranandroid.customview.scrollview | ||
|
||
import android.animation.ObjectAnimator | ||
import android.content.Context | ||
import android.graphics.Path | ||
import android.os.Build | ||
import android.util.AttributeSet | ||
import android.view.MotionEvent | ||
import android.widget.LinearLayout | ||
import androidx.annotation.Nullable | ||
import androidx.annotation.RequiresApi | ||
|
||
|
||
class ScrollLinearLayout ( | ||
@Nullable context: Context?, | ||
@Nullable attrs: AttributeSet?, | ||
defStyleAttr: Int | ||
) : | ||
LinearLayout(context!!, attrs, defStyleAttr) { | ||
|
||
|
||
private var lastX = 0 | ||
private var lastY = 0 | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) | ||
override fun onTouchEvent(event: MotionEvent): Boolean { | ||
val x = event.x.toInt() | ||
val y = event.y.toInt() | ||
when (event.action) { | ||
MotionEvent.ACTION_DOWN -> { | ||
lastX = x | ||
lastY = y | ||
} | ||
MotionEvent.ACTION_UP -> { | ||
val offX: Int = x - lastX | ||
val offY: Int = y - lastY | ||
animationScroll(getX() + offX, getY() + offY) | ||
} | ||
} | ||
return true | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) | ||
fun animationScroll(dx: Float, dy: Float) { | ||
val path = Path() | ||
path.moveTo(dx, dy) | ||
val objectAnimator = ObjectAnimator.ofFloat(this, "x", "y", path) | ||
objectAnimator.start() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<resources> | ||
|
||
|
||
|
||
|
||
<declare-styleable name="FragmentTop"> | ||
<!-- 左边文字大小--> | ||
<attr name="scroll_control1" /> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="FragmentBottom"> | ||
<!-- 左边文字大小--> | ||
<attr name="scroll_control1" /> | ||
</declare-styleable> | ||
|
||
</resources> |