2013-10-18 161 views
0

我有一個看起來像這樣的一個活動放置一個按鈕:根據背景

activity ui

當我運行模擬器上的應用,圖釘還沒有結束的即時貼,所以我知道不同大小的屏幕會出現問題。便條紙和軟木板是背景。我怎麼能做到這一點,以便在任何尺寸的屏幕上,圖釘將在正確的位置?它目前是線性佈局。

+0

爲什麼不發表一些你已經試過的代碼?這更有可能吸引答案 – Martin

+0

我只嘗試過佈局權重,我主要在尋找想法來嘗試,而不一定是解決方案。 –

+0

相信我,對您來說最便利的想法是使用RelativeLayout,因爲您將其他視圖用作參考點,並且由於您可以方便地將它們放置在任何你喜歡的位置。我還假設你會希望在postit中放置文本,使用相關佈局,你可以將參考點放置在彼此的頂部。是的,請使用權重來方便地調整其他設備的大小。 – ChallengeAccepted

回答

1

最適合您的解決方案是使用RelativeLayout。我建議您的便箋不是背景的一部分,而是自己的ImageView,以便隨時調整大小以適合任何屏幕。由於這個原因,你可以將它添加到你的軟木的代碼中。

<ImageView 
android:id="@+id/cork" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_centerHorizontal="true" 
android:layout_alignTop="@+id/postit_note" 
/> 

它會將軟木居中並將其對齊到便條紙的頂部。

您可以查看所有其他屬性,以幫助您根據上述建議RelativeLayouts Here

0

,做這樣的事情:

<RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

     <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView" 
       android:layout_alignParentTop="true" 
       android:src="@drawable/postit"/> 

     <ImageButton 
       android:id="@+id/angry_btn" 
       android:background="@drawable/pushpin" 
       android:layout_width="80dp" 
       android:layout_height="80dp" 
       android:shadowDx="0" 
       android:shadowDy="0" 
       android:layout_gravity="center" 
       android:shadowRadius="5" 
       android:layout_centerHorizontal="true" 
       android:layout_alignParentTop="true"/> 

    </RelativeLayout> 

注意:應使棕色部分爲背景對於最外面的佈局,並且爲便條紙設置單獨的圖像,您應該將其設置爲上面顯示的圖像視圖。