这是正确的xml布局

时间:2014-03-04 09:44:11

标签: android android-layout android-linearlayout relativelayout

我已为此UI编写了xml布局。我想知道这是不是正确的方式。右边我的意思是它应该是一个相对布局还是单独的线性布局水平

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/background_repeat"
    android:tileMode="repeat" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:paddingBottom="25dp"
        android:paddingLeft="35dp"
        android:paddingRight="35dp" >

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="50dp"
            android:layout_height="45dp"
            android:src="@drawable/user" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="45dp"
            android:layout_marginTop="0.4dp"
            android:layout_weight="0.41"
            android:background="@drawable/username_textbox"
            android:ems="10"
            android:minWidth="110dp"
            android:paddingLeft="8dp"
            android:singleLine="true" >
        </EditText>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout1"
        android:paddingLeft="35dp"
        android:paddingRight="35dp" >

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="50dp"
            android:layout_height="45dp"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/password_icon" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="45dp"
            android:layout_marginTop="0.4dp"
            android:background="@drawable/username_textbox"
            android:ems="10"
            android:minWidth="110dp"
            android:paddingLeft="8dp"
            android:singleLine="true" >
        </EditText>
    </LinearLayout>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:background="@drawable/background_signin"
        android:text="Login"
        android:textColor="#ffffff" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="175dp"
        android:layout_height="207dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="85dp"
        android:paddingBottom="20dp"
        android:src="@drawable/app_logo" />

</RelativeLayout>

enter image description here

1 个答案:

答案 0 :(得分:1)

您应该只使用一个垂直布局。因为所有视图都是垂直对齐的。编辑文本的图像可以在xml中使用Drawable {Left}属性

在XML

android:drawableLeft="@drawable/icon"

或致电

EditText text = (EditText)findViewById(R.id.text);
 text.setCompoundDrawables(null, null, getResources().getDrawable(R.drawable.check_box), null);
相关问题