Tag: android view

缩放根视图后,子视图不可单击

我正在缩放rootView ,它是rootView fragment的LinearLayout ,但子视图不可clickable 。 这是rootView public class CarouselLinearLayout extends LinearLayout { private float scale = CarouselPagerAdapter.BIG_SCALE; public CarouselLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); } public CarouselLinearLayout(Context context) { super(context); } public void setScaleBoth(float scale) { this.scale = scale; this.invalidate(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // The main mechanism to display […]

MPAndroidChart条形图 – 如何在组之间对随机x轴间隔的条形图进行分组?

我想制作一个条形图,其中3个不同的数据集在每个数据点组合在一起,如下所示: 但是,我无法使用库提供的groupBars方法将条形组合在一起,因为无论我为条目设置了什么x值,它都会根据我在参数中指定的间隔对条形图进行分组。 例如,如果我生成一个带有条目x值{0,5,13,​​17 … 50}并调用`groupBars’的数据集,那么我的所有条目都会被收集1 x值,如下所示: 我想要的是每个被分组的条形图,每个条形图在其指定的x值处可见。 如果我只是删除groupBars调用,我会得到类似于我想要的东西但不完全,因为条形图都是重叠的,如下所示: 如何获得与上图类似的结果,但每个数据集的条形图是否完全可见? 这是我生成数据集和分组条形码的代码: ArrayList happinessValues = new ArrayList(); ArrayList stressValues = new ArrayList(); ArrayList painValues = new ArrayList(); for (int i = 0; i interval per “group” mChart.groupBars(startTime, groupSpace, barSpace);

在非UI线程上实例化视图

我知道UI元素(视图层次结构)可能只能从UI线程中操作。 对于后台操作,可以使用AsyncTask,它提供事件处理程序以访问UI线程。 简而言之,是否允许在非UI线程中实例化View(与getApplicationContext() )? 此自定义View后代 – 一旦实例化 – 将从UI线程添加到视图层次结构中。 所以只有构造函数调用是在Asynctask.doInBackground() ; 它附加( addView(…) )到Activity的根布局层次结构仍然在UI线程中完成。 详情如下: public MyView extends View { public MyView(Context context) { … } … } 我制作了一个自定义视图,重写了onDraw(…)等。 当用户单击我的主Activity中的某个MenuItem时,会创建另一个Activity(MyOtherActivity)并显示哪个屏幕正好是MyView 由于MyOtherActivity的屏幕必须立即显示,我在AsyncTask中预先实例化MyView,而用户在主Activity中的其他位置(即他还没有点击那个MenuItem)。 MyView引用存储在静态数据成员中。 调用MyOtherActivity.onCreate() ,其构造函数代码从静态获取MyView,并通过addView(…)将其添加到其布局根层次结构中。 (我知道静态变量可能会引入内存泄漏,所以一旦不需要,我就把它设置为null 。) MyView是否在另一个线程中实例化(并在其构造函数中获取getApplicationContext()的返回值getApplicationContext()是不是问题(可能会引入意外问题)?

无法实例化类……; 没有空的构造函数

当我运行我的PaintView.java ,我在logcat中收到以下错误,即无法实例化类com.example.connectthedots.PaintView ; 没有空的构造函数。 07-22 18:47:43.453: D/dalvikvm(19728): newInstance failed: no () 07-22 18:47:43.453: D/AndroidRuntime(19728): Shutting down VM 07-22 18:47:43.453: W/dalvikvm(19728): threadid=1: thread exiting with uncaught exception (group=0x41bf6da0) 07-22 18:47:43.453: E/AndroidRuntime(19728): FATAL EXCEPTION: main 07-22 18:47:43.453: E/AndroidRuntime(19728): Process: com.example.connectthedots, PID: 19728 07-22 18:47:43.453: E/AndroidRuntime(19728): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.connectthedots/com.example.connectthedots.PaintView}: java.lang.InstantiationException: can’t instantiate class com.example.connectthedots.PaintView; no […]

如何在android中选择和取消选择图像?

我正在尝试写一个项目。 在我的项目中,我可以成功拖动图像。 这是PICTURE ,这是我的ViewOnTouchListener代码: package com.seifi.dragtestapplication; import android.graphics.Point; import android.view.MotionEvent; import android.view.View; import android.widget.FrameLayout; class ViewOnTouchListener implements View.OnTouchListener { Point pushPoint, closePoint; int lastImgLeft; int lastImgTop; FrameLayout.LayoutParams viewLP; FrameLayout.LayoutParams pushBtnLP; FrameLayout.LayoutParams closeBtnLP; int lastPushBtnLeft, lastCloseBtnLeft; int lastPushBtnTop, lastCloseBtnTop; private View mPushView, mCloseView, mShadowView; ViewOnTouchListener(View mPushView, View mCloseView, View mShadowView) { this.mPushView = mPushView; this.mCloseView = […]

双击:放大Android MapView?

经过一些工作,我的路线应用程序工作正常。 我唯一想要添加的是双击放大function,但我不知道如何。 你能给我一个提示吗?