【问题标题】:Android center two text fields in a frame layout at the same timeAndroid同时在一个框架布局中居中两个文本字段
【发布时间】:2014-05-06 19:46:03
【问题描述】:

之前可能有人问过这个问题(对此我深表歉意),但我找不到它,所以我在这里。

我有一个水平和垂直居中的框架布局。里面有两个editText,我想把它们都安排到屏幕的中心,同时保持它们之间的一定距离。

我希望我的画能让你知道我想要什么。

我尝试了很多东西,但似乎还不够。感谢您的帮助,抱歉打扰了!

http://oi59.tinypic.com/qxa2vm.jpg

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" >

    <EditText
        android:id="@+id/editText_nume"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="@string/nume" />

    <EditText
        android:id="@+id/editText_parola"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:text="@string/parola" />
</FrameLayout>

【问题讨论】:

    标签: android xml layout frame


    【解决方案1】:

    使用LinearLayout 代替FrameLayoutFrameLayout 设计用于在屏幕上屏蔽一个区域以显示单个项目。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:orientation="vertical" >
    
            <EditText
                android:id="@+id/editText_nume"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:text="@string/nume" />
    
            <EditText
                android:id="@+id/editText_parola"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:inputType="textPassword"
                android:text="@string/parola" />
    
        </LinearLayout>
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-16
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多