屏幕中心的文本视图-xamarin

时间:2016-09-10 09:03:36

标签: android-layout xamarin responsive

我正在开发xamarin餐厅的android应用程序,所以我正在设计登录屏幕 因为我添加了文本视图“USERNAME”现在我希望这个文本视图出现在屏幕的中心我想要硬编码,我希望它是响应。请指导如何在中心,因为我是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>

1 个答案:

答案 0 :(得分: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>