2016-09-10 69 views
0

我正在開發android應用程序的餐廳上xamarin,所以我設計登錄屏幕 爲我添加文本視圖「USERNAME」現在我想這個文本視圖出現在中心的屏幕我不想要硬編碼,我希望它是響應。請指導如何在中心,因爲我是新的xamarin這裏是我的代碼textview在屏幕中心-xamarin

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ddd9db" 
    android:theme="@style/Theme.Custom"> 
    <TextView 
     android:text="UserName" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:layout_width="148.0dp" 
     android:layout_height="37.0dp" 
     android:gravity="center" 
     android:id="@+id/textView_user" 
     android:fontFamily="@string/Hello" 
     android:textColor="@android:color/black" 
     android:layout_centerInParent="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="24.0dp" 
     android:inputType="text" 
     android:textSize="25px" 
     android:textAlignment="gravity" 
     android:theme="@style/Theme.Custom" 
     android:layout_marginLeft="225dp" /> 
    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="46.0dp" 
     android:id="@+id/editText_user" 
     android:textColor="@android:color/black" 
     android:fontFamily="@string/Hello" 
     android:background="@drawable/EditTextStyle" /> 
    <TextView 
     android:text="Password" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView_pass" 
     android:layout_marginTop="29.0dp" 
     android:textSize="25px" 
     android:fontFamily="@string/Hello" 
     android:textColor="@android:color/background_dark" /> 
    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="43.0dp" 
     android:id="@+id/editText_pass" 
     android:textColor="@android:color/black" 
     android:fontFamily="@string/Hello" 
     android:background="@drawable/EditTextStyle" /> 
    <FrameLayout 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/frameLayout1" /> 
    <Button 
     android:text="Button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/button1" 
     android:textColor="@android:color/background_dark" 
     android:layout_marginRight="0.0dp" 
     android:layout_marginLeft="0.0dp" 
     android:theme="@style/Theme.Custom" /> 
</LinearLayout> 

回答

0

試試這個代碼。你必須使用layout width =「match_parent」和gravity =「center」

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ddd9db" 
    android:theme="@style/Theme.Custom" 
    android:gravity="center"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout1" 
     android:background="@android:color/background_light"> 
     <TextView 
      android:text="UserName" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_width="match_parent" 
      android:layout_height="37.0dp" 
      android:gravity="center" 
      android:id="@+id/textView_user" 
      android:fontFamily="@string/Hello" 
      android:textColor="@android:color/black" 
      android:layout_centerInParent="true" 
      android:layout_centerHorizontal="true" 
      android:inputType="text" 
      android:textSize="25px" 
      android:textAlignment="gravity" 
      android:theme="@style/Theme.Custom" /> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="46.0dp" 
      android:id="@+id/editText_user" 
      android:textColor="@android:color/black" 
      android:fontFamily="@string/Hello" 
      android:background="@drawable/EditTextStyle" /> 
     <TextView 
      android:text="Password" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView_pass" 
      android:layout_marginTop="29.0dp" 
      android:textSize="25px" 
      android:fontFamily="@string/Hello" 
      android:textColor="@android:color/background_dark" 
      android:gravity="center" /> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="43.0dp" 
      android:id="@+id/editText_pass" 
      android:textColor="@android:color/black" 
      android:fontFamily="@string/Hello" 
      android:background="@drawable/EditTextStyle" /> 
     <FrameLayout 
      android:minWidth="25px" 
      android:minHeight="25px" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/frameLayout1" /> 
     <Button 
      android:text="Button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/button1" 
      android:textColor="@android:color/background_dark" 
      android:layout_marginRight="0.0dp" 
      android:layout_marginLeft="0.0dp" 
      android:theme="@style/Theme.Custom" /> 
    </LinearLayout> 
</LinearLayout>