我是android开发的新手。我想在更改图像大小的同时将我的图像从中心移到屏幕的右上角(Smaller)。我尝试了以下操作-对translationX和translationY进行硬编码,输入-150dp这样的特定值,在我的仿真器屏幕上看起来不错,但是在各种设备上的图像位置都不同。.getX。getY方法,我试图在图像中放置一个不可见的图像(alpha 0),并在图像中放置getx和y并设置translationx,y,但它不起作用,该图像从我的屏幕上滑落。我想如果我能得到像textview这样的对象的位置并将图像位置设置为objectposition + somevalue会起作用,但是我不知道该怎么做。有人可以帮我吗?这是我正在尝试做的图像。提前致谢。
2 回答
![?](http://img1.sycdn.imooc.com/54584c9c0001489602200220-100-100.jpg)
慕的地8271018
TA贡献1796条经验 获得超4个赞
试试这个,希望这段代码对您有所帮助
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Your Text" android:layout_gravity="center"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/star_big_off" /></LinearLayout>
添加回答
举报
0/150
提交
取消