2017-05-08 187 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。 –