问题描述
|
亲爱的所有人,我正在尝试设置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);