2014-06-15 100 views
0

我工作的一個MP3播放器,我才意識到我的main_activity.xml被搞砸MP3播放器搞砸按鈕

我有3個按鈕,上一個,播放/暫停和下一步如圖here

我只有1個聲望點,所以暫時沒有圖片上傳。

這裏的XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/layout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:orientation="vertical" 
    android:weightSum="7" 
    tools:ignore="UselessParent" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="6" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/bg" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:contentDescription="@string/Caratula" > 
     </ImageView> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/buttons" 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" 
     android:background="#FFFFFF" 
     android:gravity="center" 
     android:orientation="horizontal" 
     android:weightSum="5" > 

     <Button 
      android:id="@+id/btnPrevious" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_margin="5dp" 
      android:background="@drawable/btnprevious" 
      android:onClick="click" /> 

     <View 
      android:layout_width="0dip" 
      android:layout_height="0dip" /> 

     <Button       
      android:id="@+id/btnPlay" 
      android:layout_width="0dip" 
      android:layout_height="fill_parent" 
      android:layout_margin="5dp" 
      android:background="@drawable/play" 
      android:onClick="click" /> 



     <View 
      android:layout_width="0dip" 
      android:layout_height="0dip" /> 

     <Button 
      android:id="@+id/btnNext" 
      android:layout_width="0dip" 
      android:layout_height="fill_parent" 
      android:layout_margin="5dp" 
      android:background="@drawable/next" 
      android:onClick="click" /> 
    </LinearLayout> 
</LinearLayout> 

我會在這裏欣賞的幫助。

回答

0

我不完全知道你想怎麼的按鈕來進行佈局,但嘗試一下本作包含的按鈕LinearLayout ...

<LinearLayout 
    android:id="@+id/buttons" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="#FFFFFF" 
    android:gravity="center" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/btnPrevious" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:layout_margin="5dp" 
     android:background="@drawable/btnprevious" 
     android:onClick="click" /> 

    <View 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" /> 

    <Button       
     android:id="@+id/btnPlay" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:layout_margin="5dp" 
     android:background="@drawable/play" 
     android:onClick="click" /> 

    <View 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" /> 

    <Button 
     android:id="@+id/btnNext" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:layout_margin="5dp" 
     android:background="@drawable/next" 
     android:onClick="click" /> 
</LinearLayout> 

可以擺脫android:weightSum屬性 - 它是可選的,總重量總和將計算爲LinearLayout中小部件的所有android:layout_weight屬性的總和。使用上述方法,每個ButtonView將被分配爲LinearLayout寬度的五分之一。

+0

我收到了一些「嵌套的重量對性能不利」的警告。我應該刪除導致此錯誤的行嗎? – Slipfreak900

+0

不,這只是Android Lint迂腐。當然,嵌套的東西太多(不僅僅是重量,而是嵌套佈局)*可能會影響性能,但並不意味着它實際上會。測試一下,如果它工作的話很好。如果你能整理它並減少事情,那就這樣做。 – Squonk