本文介绍了机器人 - 定位的观点编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想弄清楚如何编程方式在Android的位置视图。让我们说,例如,我们有这个XML code。
I want to figure out how to position views programmatically in android. Lets say for example we have this XML code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLayout">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="121dp"
android:layout_marginTop="140dp"
android:text="Results" /></RelativeLayout>
我怎样才能做到这一点的布局以编程的机器人?因为我想有我的TextView中的随机位置。
How can I achieve this layout programmatically in android? because I want to have a random position of my textview.
推荐答案
检查该..
RelativeLayout main = new RelativeLayout(this);
main.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
TextView textV = new TextView(this);
textV.etGravity(Gravity.LEFT);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(121, 140, 0, 0);
textV.setLayoutParams(layoutParams);
text.setText("Result ");
main .addView(text);
这篇关于机器人 - 定位的观点编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!