2012-11-19 70 views
0

我想創建一個如下所示的佈局。Android RelativeLayout prob

model layout

對於這一點,我已經使用的代碼。如果textWoundTypeDetails文字很小,但文字很大,它會將圖像從屏幕上推開,並且文字會填滿整個寬度。

<TextView 
     android:id="@+id/textWoundType" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:padding="5dp" 
     android:text="@string/wound_screener" /> 

<ImageView 
     android:id="@+id/closebtn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dp" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/buttonclose" /> 
<ImageView 
     android:id="@+id/imgWoundType" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dp" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@+id/textWoundTypeDetails" 
     android:layout_below="@id/textWoundType" 
     android:src="@drawable/article_noimg" /> 

<TextView 
     android:id="@+id/textWoundTypeDetails" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_below="@id/textWoundType" 
     android:padding="5dp" 
     android:text="A wound caused by superficial damage to the skin, no deeper than the epidermis. It is less severe than a laceration, and bleeding, if present, is minimal." /> 

如何解決這個問題呢?

+0

您還可以使用Linearlayout進行上述佈局 –

+0

您必須對imageView使用linearLayout –

回答

0

嘗試以下代碼。我希望它能幫助你。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="2" > 

     <TextView 
      android:id="@+id/textWoundType" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_gravity="left" 
      android:layout_weight="1" 
      android:padding="5dp" 
      android:text="SCRAPES" /> 

     <ImageView 
      android:id="@+id/closebtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:padding="5dp" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="2" > 

     <ImageView 
      android:id="@+id/imgWoundType" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:padding="5dp" 
      android:src="@drawable/ic_launcher" /> 

     <TextView 
      android:id="@+id/textWoundTypeDetails" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:padding="5dp" 
      android:text="A wound caused by superficial damage to the skin, no deeper than the epidermis. It is less severe than a laceration, and bleeding, if present, is minimal." /> 
    </LinearLayout> 

</LinearLayout>