gpt4 book ai didi

java - 如何用java代码编写这个xml

转载 作者:行者123 更新时间:2023-12-01 15:50:43 25 4
gpt4 key购买 nike

Android XML:

<TextView  
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:layout_height="28dp" android:layout_width="180dp"
android:layout_toRightOf="@+id/signinemailtxt"
android:paddingLeft="50dp"
android:layout_marginTop="65dp"
android:background="#ffffff"

/>

Java:

layout=  new  RelativeLayout(this);
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
TextView Txt=new TextView(this);
Txt.setText("Name");

如何在java代码中获取layout_marginTop,layout_toRightOf选项

最佳答案

  RelativeLayout layout = new RelativeLayout(this);
TextView tv1 = new TextView(this);
tv1.setText("A");

TextView tv2 = new TextView(this);
tv2.setText("B");
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
lp.addRule(RelativeLayout.RIGHT_OF, tv1.getId());

layout.addView(tv1);
layout.addView(tv2, lp);

关于java - 如何用java代码编写这个xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6109604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com