Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:以编程方式将控件重新定位到另一个控件之下_Android - Fatal编程技术网

Android:以编程方式将控件重新定位到另一个控件之下

Android:以编程方式将控件重新定位到另一个控件之下,android,Android,我有以下xml格式。它用于相对布局中: <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:la

我有以下xml格式。它用于相对布局中:

  <TextView
    android:id="@+id/tv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>        
  <TextView
    android:id="@+id/tv2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/tv1"/>
  <TextView
    android:id="@+id/tv3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/tv2" />


在代码中,如果我删除第二个文本视图(tv2),我想将tv3重新定位到tv1下方。我找不到一种用xml实现这一点的方法,所以我想通过编程实现。我该怎么做?非常感谢

我假设它与这里的问题非常相似->

Lint报告嵌套权重的性能问题。不是很明显,但这里有另一个解决方案


RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

p.addRule(RelativeLayout.BELOW, R.id.tv1);
tv3.setLayoutParams(p);

事实上,这很接近。那篇帖子是关于重量的,它与RelativeLayout无关,这可能就是我没有找到那篇帖子的原因。不过,总的解决方案是正确的。谢谢。