如何在RelativeLayout中以编程方式设置android:orientation ="horizo​​ntal"?

Waq*_*leh 6 android android-layout

如何在RelativeLayout中以编程方式设置android:orientation ="horizo​​ntal",如下所示:

<RelativeLayout
                android:id="@+id/ID"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止:

RelativeLayout rLayout = new RelativeLayout(getActivity());
LayoutParams layoutParams;
layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
rLayout.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)

gah*_*hfy 23

正如您在文档中看到的那样,没有任何orientation争论RelativeLayout.

  • 因为ecplise IDE没有给出任何错误或警告,我认为这是必要的.而且我在运行时也没有得到错误 (2认同)