2017-02-10 30 views
0

我有三個編輯文本字段,並在我的創造(我會隱藏第二和第三編輯文本),我想顯示在中心第一編輯文本,如果第一次編輯的文本是有效的,那麼我聯合國將隱藏的第二個編輯的文字,現在我要對齊第一編輯文本和第二編輯文本應該在佈局居中....等等反之亦然佈局中心的所有元素自動

+0

in我的創建方法 –

+3

分享您的佈局xml文件 – Piyush

回答

2
android:gravity="center" 

使用此父佈局居中元素

OR

您可以使用

android:layout_gravity="center" 
在元件

在其父中心。

而對於隱藏的EditText,請使用

android:visibility="gone" 

,這樣它沒有考慮空間佈局

+0

其工作tqqq bro –

+0

請將答案標記爲已接受或正確 –

1

嘗試這種佈局`

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

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_centerInParent="true"> 

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="first edit text"/> 
    <EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="second edit text"/> 
    <EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="second edit text"/> 
</LinearLayout> 
</RelativeLayout>` 

,然後隱藏您想隱藏在java代碼中的編輯文本

+0

其工作tqqq bro –

+0

您可以檢查標記是否正常工作 –