2012-04-02 33 views
1

我想實現

我試圖做一個佈局等於下一個環節是什麼: http://www.flickr.com/photos/[email protected]/7038207573/Android的佈局,如何定位兩個圖像和搜索條

我有什麼

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

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/minVolume" 
     android:src="@drawable/ic_volume_min" /> 

    <SeekBar 
     android:id="@+id/seekBar1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/maxVolume" 
     android:src="@drawable/ic_volume_max" /> 
</LinearLayout> 

結果我得到這個代碼,seekbar延伸到正確的圖標上。

  • 我想有它適當規模的不同screenszes
  • 如果它可以不使用權重屬性,我會喜歡它的解決方案

任何建議表示讚賞

回答

1

進行相對佈局,使錨定到左側(ALIGN_PARENT_LEFT),錨定到右側(ALIGN_PARENT_RIGHT)右圖像和左圖像它們之間的seekbar與android:layout_toRightOf和android:layout_toLeftOf。

欲瞭解更多信息,請參閱文檔:http://developer.android.com/reference/android/widget/RelativeLayout.html

+0

這是在我的oppinion最好的解決方案,我正在尋找,thx莫斯 – Tobrun 2012-04-02 11:09:38

+0

@ user1281750很好的幫助! – Moss 2012-04-02 12:29:05

0

如果您爲所有三個小部件設置layout_width爲0,併爲應該工作的seekbar權重設置爲1。我不知道該怎麼做,沒有重量(爲什麼?)

+0

謝謝你的回答,真的很喜歡你的方法。我沒有提出要求的原因是要了解其他方法可能用於佈局佈局;) – Tobrun 2012-04-02 11:01:20

+0

爲什麼需要其他方法,如果這是工作方式? – 2012-04-02 13:43:58

0

使用窗口管理器來獲取大小,然後使用操作符,如「/」等調整,

Display display = getWindowManager().getDefaultDisplay(); 
int height = display.getHeight(); 
int width = display.getWidth(); 

雖然我相信新的API已經生效。

3

在SeekBar中使用android:layout_weight="0.9"

在不使用layout_weight

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 
    <ImageView 
     android:id="@+id/left" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:contentDescription="@string/minVolume" 
     android:src="@drawable/ic_volume_min" />  
    <ImageView 
     android:id="@+id/right" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/maxVolume" 
     android:src="@drawable/ic_volume_max" 
     android:layout_alignParentRight="true" />  
    <SeekBar 
     android:id="@+id/seekBar1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/left" 
     android:layout_centerVertical="true" 
     android:layout_toLeftOf="@+id/right" />  
</RelativeLayout> 
+0

@ user1281750如果您沒有得到答案,請檢查我的更新答案,它可能會對您有所幫助。 – 2012-04-02 10:46:29