【发布时间】:2018-08-23 18:07:46
【问题描述】:
我使用解决方案创建 TextView 并触摸 TextView: 这是布局 xml:我创建了 6 个 TextView 以在触摸屏幕时显示值。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/txtPreSelect1"
android:layout_width="@dimen/d_60"
android:layout_height="match_parent"
android:gravity="center"
android:text="000"
/>
<TextView
android:id="@+id/txtPreSelect2"
android:layout_width="@dimen/d_60"
android:layout_height="match_parent"
android:gravity="center"
android:text="0"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="200dp"
android:layout_height="1dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/txtSelect1"
android:layout_width="@dimen/d_60"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/d_40"
android:gravity="center"
android:text="001"
/>
<TextView
android:id="@+id/txtSelect2"
android:layout_width="@dimen/d_60"
android:layout_height="match_parent"
android:gravity="center"
android:text="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="200dp"
android:layout_height="1dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/txtNextSelect1"
android:layout_width="@dimen/d_60"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/d_40"
android:gravity="center"
android:text="002"
/>
<TextView
android:id="@+id/txtNextSelect2"
android:layout_width="@dimen/d_60"
android:layout_height="match_parent"
android:gravity="center"
android:text="2"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center|right"
android:orientation="horizontal">
<TextView
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center"
android:text="@string/btnCancel"/>
<TextView
android:id="@+id/btnOK"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="@string/btnOK"
/>
</LinearLayout>
</LinearLayout>
我在 TextViews 上创建事件 Touch,以更改 Textview 的值:
dialog.txtPreSelect1.setOnTouchListener {v: View, event: MotionEvent ->
// Perform tasks here
when (event.action)
{
MotionEvent.ACTION_DOWN ->{
yValue=event.y
}
MotionEvent.ACTION_MOVE ->{
val curentY=event.y
if(curentY>yValue)
{
if(curentY>yValue) {
yValue=curentY
var iStartValue=dialog.txtPreSelect1.text.toString().toInt() - iStep1
dialog.txtPreSelect1.text = iStartValue.toString()
iStartValue=iStartValue +iStep1
dialog.txtSelect1.text = iStartValue.toString()
iStartValue=iStartValue +iStep1 dialog.txtNextSelect1.text = iStartValue.toString()
}
}
else if(curentY<yValue)
{
if(curentY<yValue) {
yValue=curentY
var iStartValue=dialog.txtPreSelect1.text.toString().toInt() + iStep1
dialog.txtPreSelect1.text = iStartValue.toString()
iStartValue += iStep1
dialog.txtSelect1.text = iStartValue.toString()
dialog.txtNextSelect1.text = iStartValue.toString()
}
}
}
}
true
}
如何创建事件移动文本相同的图像 2? 或者 Exist other View 可以处理我的工作? 谢谢大家。
【问题讨论】:
标签: android