2013-02-25 90 views
1

下面的代碼:相對佈局給予了很多麻煩

<RelativeLayout 
     android:id="@+id/tc" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/tc" 
     android:layout_marginLeft="185dip" 
     android:layout_marginTop="25dip" 
     > 

      <ImageView 
       android:id="@+id/tc_icon" 
       android:background="@drawable/count_icon" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignBottom="@id/tc" 
       android:layout_mar 
      /> 
      <TextView 
       android:id="@+id/tc_icon_text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="5dip" 
       android:text="1" 
       android:layout_gravity="bottom" 
       android:textColor="#f7e906" 
       android:textStyle="bold" 
       />  
    </RelativeLayout> 

我也總算使圖像和文本的意見相互重疊(我想)。現在,我希望它們被放置在它們的父親RelativeLayout的左下角(ID爲'tc')....但是,它們不會移動。

如果我使用alignParentBottom ....整個相對佈局在整個屏幕上延伸並對齊到它的父親relativeLayout。

請幫忙。謝謝! :)

+2

你可以放置一個佈局的草圖? – Riskhan 2013-02-25 05:45:37

+1

提供佈局草圖........... – 2013-02-25 05:46:24

+0

alignParentBottom和父母layout_height = wrap_content相互矛盾。在佈局上應用一些高度,你會看到不同之處。 – 2013-02-25 05:57:09

回答

0

如果你想重疊一個圖像和一個文本視圖,簡單地使用android:drawableleft或ONY位置,你想要的。

例如:

<TextView
android:id="@+id/tc_icon_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:text="1"
android:layout_gravity="bottom"
android:textColor="#f7e906"
android:textStyle="bold"
android:drawableleft="@drawable/yourimage.jpg"/>

這會給你對你的TextView左側的圖像。檢查一下

+0

你能多給點解釋一下嗎?喜歡如何使用它?也許我可以谷歌如何使用drawableLeft。謝謝! – 2013-02-25 06:16:15

+0

@ParikksitBhisay:看我的編輯。我也給出了我的答案的鏈接 – 2013-02-25 06:31:53