问题描述
我正在做 2D 绘图(使用 View.onDraw)。我找到的所有例子 使用按钮在 TextView 中完成工作。我已经简化为 一个测试项目,消除了我的问题起源的任何可能性 在我更复杂的课程中。我确信我的问题一定来自 在布局中。我想我需要布局方面的帮助。
在测试中,我定义了一个圆的位置。在两个肖像 和景观:绘制定义的圆(在 onDraw() 中),其中 我很期待。
我通过 mDetector = new GestureDetectorCompat(context,gestureListener,mhandler);
和 onTouchEvent(MotionEvent event)
捕获鼠标点击
然后 private GestureDetector.OnGestureListener gestureListener = new GestureDetector.OnGestureListener()
包含 onSingleTapup(MotionEvent event)
... 我捕获 event.getX()
和 event.getY()
。最后,通过 invalidate()
,使 onDraw()
在我的接触点画一个圆圈。
纵向:圆圈出现在我的鼠标指针下方。 在横向中:圆圈出现离我的鼠标指针有一段距离。
当我在屏幕中向下单击时向左或向上单击时,绘制的点更靠右(反之亦然)。
(我在这个简化的测试项目中不做任何翻译;但在我更复杂的项目中, 平移将我绘制的对象向与鼠标移动相反的方向移动。)
我有一个 layout/activity_main 和一个 layout-land/activity_main。它们是相同的,除了 背景颜色(显示正在使用正确的布局)。
我几天来一直在处理不同的布局......试图弄清楚这一点 问题解决。
这是我当前的布局文件:
<?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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<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"
tools:showIn="@layout/activity_main">
<appview.GraphicsView
android:id="@+id/graphicsView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.15"
android:background="@color/teal_700"
android:focusableInTouchMode="true"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:rotationX="0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
有人比我更了解 Android 布局吗?请来帮助我。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)