亲爱的,我试图在appwidget中设置TextView的位置.
基本上,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);