0

我已經寫了這個UI的XML佈局。我想知道這是否正確。通過右鍵我的意思是它應該是水平這是正確的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

+0

雅它是正確的佈局。但將寬度更改爲您父級相對佈局的match_parent。 – Piyush

+0

與我寫的方式的問題是,軟鍵盤不會推動佈局頂部。它出現在文本框中。即使我修改了 meWantToLearn

+0

android:windowSoftInputMode =「adjustResize | stateVisible」>試試這個 – Piyush

回答

1

你應該只使用一個垂直佈局。因爲所有的視圖垂直神韻:都在一個相對佈局或單獨的線性佈局。編輯文本的圖像,你可以在XML

使用可繪製{}左屬性在XML

android:drawableLeft="@drawable/icon" 

或致電

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