在运行时设置的远程视窗TextView中的位置 [英] Set position of TextView in RemoteView during runtime

查看:187
本文介绍了在运行时设置的远程视窗TextView中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,我想设置一个appwidget内一个TextView的位置。

基本上,直达性房颤TextView的作品:

  myRemoteView.setTextColor(R.id.myTextView,Color.WHITE); //作品
 

也间接,我可以访问TextView的属性:

  myRemoteView.setInt(R.id.myTextView,setTextColor,Color.BLUE); // 作品
 

和设置浮点值,也可以工作:

  myRemoteView.setFloat(R.id.myTextView,setTextSize,25); // 作品
 

现在我想用5个像素来移动的TextView的x位置:

  myRemoteView.setFloat(R.id.myTextView,setTranslationX,5); //不起作用
myRemoteView.setFloat(R.id.myTextViewsetX的,5); //不起作用
myRemoteView.setInt(R.id.myTextViewsetLeft,5); //不起作用
 

我试过的FrameLayout和RelativeLayout的,也AbsoluteLayout(德preciated)。没有什么作品。但是,必须有办法做到这一点。能否请你帮忙吗?

解决方案

 的LayoutParams LP = myRemoteView.getLayoutParams();
lp.marginLeft = 5;
myRemoteView.setLayoutParams(LP);
 

Dear all, I am trying to set the position of a TextView within an appwidget.

Basically, the direct access to properties af the TextView works:

myRemoteView.setTextColor(R.id.myTextView, Color.WHITE);   //works

Also indirectly, I can access the TextView properties:

myRemoteView.setInt(R.id.myTextView, "setTextColor", Color.BLUE); // works

And setting float values also works:

myRemoteView.setFloat(R.id.myTextView, "setTextSize", 25); // works

Now I'm trying to shift the x position of the TextView by 5 pixels:

myRemoteView.setFloat(R.id.myTextView, "setTranslationX", 5); // does not work
myRemoteView.setFloat(R.id.myTextView, "setX", 5); // does not work
myRemoteView.setInt(R.id.myTextView, "setLeft", 5); // does not work

I tried FrameLayout and RelativeLayout, and also AbsoluteLayout (depreciated). Nothing works. But there must be a way to do that. Can you please help?

解决方案

LayoutParams lp = myRemoteView.getLayoutParams();
lp.marginLeft = 5; 
myRemoteView.setLayoutParams(lp);

这篇关于在运行时设置的远程视窗TextView中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆