当前位置: 代码迷 >> Android >> android怎么设置控件位置
  详细解决方案

android怎么设置控件位置

热度:79   发布时间:2016-05-01 21:19:12.0
android如何设置控件位置?
我想在LAYOUT上动态地添加TEXT,请问如何根据自定义的X,Y值来设置TEXT的位置呢??

------解决方案--------------------
android:layout_x="0.0dip"
android:layout_y="0.0dip"
------解决方案--------------------
android:layout_x="0.0dip"
android:layout_y="0.0dip"
------解决方案--------------------
绝对布局
------解决方案--------------------
楼上的几位,楼主说的是动态添加,放在xml里面怎么动....
你可以在你的代码里面实现
比如
TextView mTextView = new TextView(context);
mTextView.setPadding(left, top, right, bottom);// 通过自定义坐标来放置你的控件
或者
TextView mTextView = new TextView(context);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)xxxx.getLayoutParams();
params.setMargins(left, top, right, bottom));// 通过自定义坐标来放置你的控件
mTextView .setLayoutParams(params);

希望对你有帮助



------解决方案--------------------
1-3楼都是坑爹的,4楼正解!
------解决方案--------------------
鄙视那种不看清问题的顶4楼
------解决方案--------------------
动态显示控件就要在代码里定义控件,同意四楼,正解!!
  相关解决方案