2012-01-25 78 views
-1

我在爲我的活動設置佈局時遇到困難。我試圖實現一個列表佈局,列表中的每一行都包含圖標,每個圖標旁邊有兩個EditText視圖。Android佈局:每行一個圖像和兩個EditText視圖

例如,GMail圖標,用戶可以在視圖中輸入他們的電子郵件和密碼。

我試過兩種方法,似乎無法得到一個工作。我最近來的是每行一個EditText視圖,但這不是我想要實現的。

下面看看我的xml。如果任何人有任何建議,我該如何改善這將是偉大的。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="5dp" > 
    <RelativeLayout > 
     <ImageView 
      android:id="@+id/logo" 

      android:layout_width="150px" 
      android:layout_height="150px" 

      android:layout_alignParentTop="true" 
      android:layout_alignParentBottom="true" 

      android:src="@drawable/gm" > 
     </ImageView> 
     <EditText 
      android:id="@+id/secondLine" 
      android:layout_width="200dp" 
      android:layout_height="wrap_content" 

      android:layout_alignRight="@id/logo" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      > 
     </EditText> 
     <EditText 
      android:id="@+id/firstLine" 
      android:layout_width="200dp" 
      android:layout_height="wrap_content" 
      android:layout_alignRight="@id/logo" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_above="@id/secondLine"> 
     </EditText> 
    </RelativeLayout> 
</LinearLayout> 
+2

你看過的文章[佈局技巧:建立高效的佈局(http://developer.android.com/resources/articles/layout-tricks-efficiency.html)。它有一個例子,聽起來像你想要做的。 –

回答

1

你必須閱讀更多的佈局。您正在將圖像設置爲父母的上方和下方。這完全沒有意義。如果這是您的列表視圖項目行,請更改爲此。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:padding="5dp" > 

<RelativeLayout 
android:orientation="horizontal" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 

<ImageView 
    android:id="@+id/logo" 
    android:layout_width="150px" 
    android:layout_height="150px" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:src="@drawable/gm" > 
</ImageView> 

<EditText 
    android:id="@+id/firstLine" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@id/logo" 
    > 
</EditText> 

<EditText 
    android:id="@+id/secondLine" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@id/logo" 
    android:layout_alignParentRight="true" 
    android:layout_alignRight="@id/firstLine" 
    > 
</EditText> 

+0

謝謝,這工作得很好,當然我需要閱讀我忘記了很多的佈局。 – Jnanathan

相關問題