2013-05-10 62 views
0

我想創建一個註釋區域,並且我正在嘗試做一個註釋設計,每個註釋都包含文本+成員圖標+成員名稱...我正在嘗試寫這樣但該圖標不斷出現在會員名稱上,任何幫助表示讚賞。android相對跳出的圖像

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<TextView 
    android:id="@+id/txtMemberName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true"/> 

    <TextView 
    android:id="@+id/txtComment" 
    android:paddingLeft="50dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/txtMemberName"/> 


    <ImageView 
    android:id="@+id/imgIcon" 
    android:paddingTop="30dp"   
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/txtMemberName" > 
</ImageView> 

+0

你能否解釋一下你想要的佈局 - 你想用文字和圖像,然後水平佈局或2行? – 2013-05-10 22:23:54

回答

1

使用LinearLayout安排領域。其中一個LinearLayout將從右到左(用戶名/圖像區域從註釋區域)分開,另一個內部爲LinearLayout以分開從上到下(用戶圖像中的用戶名)。

這是代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/txtMemberName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <ImageView 
      android:id="@+id/imgIcon" 
      android:paddingTop="30dp"   
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

    <TextView 
     android:id="@+id/txtComment" 
     android:paddingLeft="50dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 
+0

謝謝你的修改,線性佈局高度改變它wrap_content不match_parent,非常感謝。 – 2013-05-10 23:55:24

+0

當然。嘗試儘可能多地使用「RelativeLayout」。你不知道有多少次我看到人們抱怨說它不能正常工作...... – tbkn23 2013-05-11 07:23:48