Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RemoteView在视图类中不工作_Android_View_Remoteview - Fatal编程技术网

Android RemoteView在视图类中不工作

Android RemoteView在视图类中不工作,android,view,remoteview,Android,View,Remoteview,我正在视图类中创建自定义UI,并在其中创建了RemoteView,但它不起作用 视图类 public class CustomeView extends View { Bitmap icon; float left=0; RemoteViews rs; int width=0,height=0; float def_value=0; boolean unlock=false; public CustomeView(Context con

我正在视图类中创建自定义UI,并在其中创建了RemoteView,但它不起作用

视图类

public class CustomeView extends View {

    Bitmap icon;
    float left=0;
    RemoteViews rs;
    int width=0,height=0;
    float def_value=0;
    boolean unlock=false;

    public CustomeView(Context context, AttributeSet attrs) {
        super(context, attrs);
        icon=BitmapFactory.decodeResource(getResources(), R.drawable.icon);
        rs=new RemoteViews(context.getPackageName() ,R.layout.custom_ui);

        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        width = display.getWidth();
        height = display.getHeight();

        left=width/2;
        def_value=left;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        Paint a=new Paint();
        a.setTextSize(10);

        canvas.drawBitmap(icon, left, 0, null);
        canvas.drawText(String.valueOf(unlock), 0, 110, a);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
           setMeasuredDimension(width, height);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        if(event.getAction()==MotionEvent.ACTION_MOVE){
            left=event.getX()-(icon.getWidth()/2);
            isUnlock();
        }
        else if (event.getAction()==MotionEvent.ACTION_UP) {
            if(def_value!=left){
                left=def_value;
            }
        }
        invalidate();
        return true;
    }

    protected void isUnlock() {
        if(left<=20){           
            unlock=true;
            rs.setTextViewText(R.id.tvStatus, "True");
        }
        if(left>=width-20){
            unlock=true;
            rs.setTextViewText(R.id.tvStatus, "True");
        }
    }
}
public类CustomeView扩展视图{
位图图标;
左浮动=0;
远视者;
整数宽度=0,高度=0;
浮动def_值=0;
布尔解锁=假;
公共自定义视图(上下文、属性集属性){
超级(上下文,attrs);
icon=BitmapFactory.decodeResource(getResources(),R.drawable.icon);
rs=新的远程视图(context.getPackageName(),R.layout.custom_ui);
WindowManager wm=(WindowManager)context.getSystemService(context.WINDOW\u服务);
Display Display=wm.getDefaultDisplay();
宽度=display.getWidth();
高度=display.getHeight();
左=宽度/2;
def_值=左侧;
}
@凌驾
受保护的void onDraw(画布){
//TODO自动生成的方法存根
super.onDraw(帆布);
油漆a=新油漆();
a、 setTextSize(10);
画布.drawBitmap(图标,左,0,空);
drawText(String.valueOf(unlock),0,110,a);
}
@凌驾
测量时的保护空隙(内部宽度测量等级、内部高度测量等级){
设置测量尺寸(宽度、高度);
}
@凌驾
公共布尔onTouchEvent(运动事件){
//TODO自动生成的方法存根
if(event.getAction()==MotionEvent.ACTION\u MOVE){
左=event.getX()-(icon.getWidth()/2);
isUnlock();
}
else if(event.getAction()==MotionEvent.ACTION\u UP){
如果(定义值!=左){
左=def_值;
}
}
使无效();
返回true;
}
受保护的void isUnlock(){
如果(左=宽度-20){
解锁=真;
rs.setTextViewText(R.id.tvStatus,“True”);
}
}
}
自定义ui.xml布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.example.helloworl.CustomeView 
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <TextView
        android:id="@+id/tvStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="154dp"
        android:text="False" />

</RelativeLayout>


RemoteViews正在更改isUnlock方法中TextView的值,但它不起作用。

您不能将自定义视图与
RemoteViews一起使用,因为其他进程无权访问您的Java代码

我应该用什么,我正在使锁屏,位图对象向左和向右移动,我想要,如果位图对象向左移动,到达某个点后,解锁屏幕。那么告诉我该如何解决这个问题?@user2290872:你想做的可能超出了应用程序小部件的一般功能,更不用说安卓4.2+锁屏上的小部件了。也就是说,您需要坚持应用程序小部件支持的UI小部件:但我正在制作锁屏小部件。我正在制作锁屏,所以如果你有任何想法,请告诉我me@user2290872:使用母语的开发人员支持网站可能会让您更幸运。我有许多这样的网站列在。希望有一个能满足你的需要。