2017-05-08 188 views
0

我有两个布局的一个相对布局的另外一个是线性 布局......相对布局是父布局,而布局直线是相对布局的 子布局。 ......这简直是我要对齐直线 布局layout_centerInParent ...它的工作原理XML中,但我想 改变它编程如何改变线性布局对齐centerInParent编程

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World"/> 
</LinearLayout> 

回答

-1
LinearLayout.LayoutParams myLay= new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); 
myLay.gravity = Gravity.CENTER; 
+0

的问题是关于居中线性布局而不是textview – Nabin

+0

@Spiderman,我错误地提到了textview。现在检查我的答案。 –

+0

@Spiderman,并没有必要downvote。 –