在运行时设置TextView在RemoteView中的位置

问题描述

| 亲爱的所有人,我正在尝试设置TextView在appwidget中的位置。 基本上,可以直接访问TextView的属性
myRemoteView.setTextColor(R.id.myTextView,Color.WHITE);   //works
也可以间接地访问TextView属性
myRemoteView.setInt(R.id.myTextView,\"setTextColor\",Color.BLUE); // works
并设置浮点值也可以:
myRemoteView.setFloat(R.id.myTextView,\"setTextSize\",25); // works
现在,我尝试将TextView的x位置偏移5个像素:
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
我尝试了FrameLayout和RelativeLayout以及AbsoluteLayout(已贬值)。什么都没有。但是必须有一种方法可以做到这一点。你能帮忙吗?     

解决方法

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...