2015-05-26 42 views
-4
<TextView 
    android:id="@+id/aaa" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/xxx" /> 

如何以编程方式删除或添加TextView中的layout_below?Android如何以编程方式将layout_below更改为TextView

+0

请告诉我更多的东西..?如果你需要答案,你需要有效地解释事情..? – GvSharma

+2

将光标放在行尾,然后点击退格键,直到行被删除。晚点再谢我。 –

+0

你想要什么 – Prashant

回答

1

我看到2种方式。

第一种方式,您需要使用相同的名称,但在文件夹中创建layout-land新的布局,这里复制的所有内容,并删除layout_below规则。 在这种情况下,你只需要声明另一个布局,其中不包含layout_below规则

看到这个截图:

​​

这意味着,你定义了不同的方向不同的布局。 在layout/my_layout.xml

<TextView 
     android:id="@+id/aaa" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/xxx" /> 

layout-land/my_layout.xml

<TextView 
      android:id="@+id/aaa" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

欲了解更多信息,请参阅this链接:

表2.配置限定符名称,名称为 “屏幕方向”

方式二,在Java代码中(的onCreate(),例如法):

if(Activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){ 
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) yourView.getLayoutParams(); 
    lp.addRule(RelativeLayout.BELOW, 0); 
    yourView.setLayoutParams(lp); 
} 

EDITED

+1

我不明白最后一行'yourView.setLayoutParams(p);'什么是'p',哪里是'aaa'和'xxx '? –

+1

@HananAYousef,不是'p',而是'lp'。关于'xxx' - https://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html#attr_android:layout_below – Alexander

相关问题