View中的scrollby记录
想象中的scrollBy和我运行的不同,做个记录:
activity:
class TestScroller : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test_scroller)
scroller1.setOnClickListener {
scroller1.scrollBy(-100,0)
}
ll_scroller.setOnClickListener {
ll_scroller.scrollBy(-100,0)
// ll_scroller.invalidate()
}
}
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".TestScroller">
<Button
android:id="@+id/scroller1"
android:text="测试Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/ll_scroller"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/scroller2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试LinearLayout" />
</LinearLayout>
</LinearLayout>
结果:
1 : 里面的字会动,但是button不会动
2 :不会动 没有监听都
3 :不会动,因为外面的onclick被里面的button处理了也不会动
4 :会像右移动