2015-07-09 73 views
1

由於某種原因,我的seekbar非常小。我希望我的搜索欄長度至少佔用父視圖長度的一半。下面是我的XML文件:更改Seekbar的長度xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <SeekBar 
     android:rotation="270" 
     android:id="@+id/volumeBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="10px" 
     android:layout_gravity="center" /> 
</LinearLayout> 

改變layout_height到設定值(如70DP)似乎並沒有解決問題。我怎樣才能通過xml操作這個seekbar的長度?

回答

3

即使您將它旋轉爲垂直,寬度仍然是您如何修改SeekBar的長度。

例如,與該XML:

<SeekBar 
    android:rotation="270" 
    android:id="@+id/volumeBar" 
    android:layout_width="140dp" 
    android:layout_height="wrap_content" 
    android:layout_margin="10px" 
    android:layout_gravity="center" /> 

下面是結果:

enter image description here

與這個XML:

<SeekBar 
    android:rotation="270" 
    android:id="@+id/volumeBar" 
    android:layout_width="340dp" 
    android:layout_height="wrap_content" 
    android:layout_margin="10px" 
    android:layout_gravity="center" /> 

下面是結果:

enter image description here

+0

感謝您的好評,我喜歡你的格式。但是,當我改變寬度時,我的seekbar完全消失。它仍然可以在View預覽(在Android Studio中)看到,但是當我在設備上運行我的應用程序時,seekbar無處可尋。思考? – Cody

+0

似乎除了「wrap_content」之外的任何值或寬度都會使seekbar消失。你認爲這個問題與LinearLayout是否是seekbar的父對象有關?我真的很困惑,在這麼簡單的xml佈局中會出現什麼問題。 – Cody

+0

不幸的是,這並沒有解決問題。如果我將seekbar寬度更改爲硬編碼的dp值,而父視圖是線性佈局,則該條消失完全。如果我將父視圖更改爲相對佈局,當我對dp值進行硬編碼時,搜索欄寬度不會更改。我可能需要爲此打開一個新問題。 – Cody