2015-05-04 80 views
-2

現在我的列表視圖位於最後一個按鈕的右側,但我希望它位於所有三個按鈕(全部位於同一行)下方。我怎樣才能得到我的按鈕下我的列表視圖?如何獲取按鈕下方的ListView

這裏是我的代碼

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_gravity="center_horizontal|bottom" 
android:orientation="horizontal" 
android:background="#000000" 
tools:context=".Visualizer" 
android:id="@+id/homePage"> 

<ImageButton 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:gravity="top|left" 
    android:background="@drawable/pic_icon" 
    android:id="@+id/picButton" 
    android:layout_gravity="left"/> 

<ImageButton 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:gravity="top|center" 
    android:background="@drawable/cancel_that_pic" 
    android:id="@+id/deletePicButton" 
    /> 

<ImageButton 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:gravity="top|right" 
    android:background="@drawable/visual_blueblue" 
    android:id="@+id/visIcon" 
    android:layout_gravity="right" 
    /> 

<ListView 
    android:id="@+id/song_list" 
    android:layout_width="fill_parent" 
    android:layout_height="500dp" > 
</ListView> 

<Space 
    android:id="@+id/blank_space" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_horizontal" /> 


</LinearLayout> 
+0

您是否嘗試過機器人:方向= 「垂直」? 因爲我在路上不能運行你的代碼,對不起。 – Paramone

+4

我不能在你的xml代碼中看到任何TextView。 –

+1

XML文件中的textview在哪裏? –

回答

1

我不知道如果這個結構真的是你想要的,因爲一切是水平的。我會優先設置父LinearLayout垂直,然後添加另一個LinearLayout。例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="center_horizontal|bottom" 
android:orientation="vertical" 
android:background="#000000" 
tools:context=".Visualizer" 
android:id="@+id/homePage"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal|bottom" 
    android:orientation="horizontal" 
    android:background="#000000"> 

<ImageButton 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:gravity="top|left" 
    android:background="@drawable/pic_icon" 
    android:id="@+id/picButton" 
    android:layout_gravity="left"/> 

<ImageButton 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:gravity="top|center" 
    android:background="@drawable/cancel_that_pic" 
    android:id="@+id/deletePicButton"/> 

<ImageButton 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:gravity="top|right" 
    android:background="@drawable/visual_blueblue" 
    android:id="@+id/visIcon" 
    android:layout_gravity="right"/> 
</LinearLayout> 
<ListView 
    android:id="@+id/song_list" 
    android:layout_width="match_parent" 
    android:layout_height="500dp" > 
</ListView> 

<Space 
    android:id="@+id/blank_space" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_horizontal" /> 


</LinearLayout> 

而且,請使用xml屬性「match_parent」而不是「fill_parent」。此外,您可能需要在這裏做更多的事情,在一些小屏幕上可能會發生,並非所有事情都可見,因爲您的列表視圖高度爲500dp。

+0

非常感謝!這正是我正在尋找的東西,我現在要做的就是調整前三個按鈕的大小,以便填充空白區域,然後設置! :D –

+0

最好的辦法是爲每個ImageButton提供android:layout_weight =「1」,併爲每個ImageButton設置android:scaleType =「centerInside」... – Opiatefuchs

0

試試這個,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/homePage" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center_horizontal|bottom" 
    android:background="#000000" 
    android:orientation="vertical" 
    tools:context=".Visualizer" > 

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

     <ImageButton 
      android:id="@+id/picButton" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_gravity="left" 
      android:background="@drawable/ic_launcher" 
      android:gravity="top|left" /> 

     <ImageButton 
      android:id="@+id/deletePicButton" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:background="@drawable/ic_launcher" 
      android:gravity="top|center" /> 

     <ImageButton 
      android:id="@+id/visIcon" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_gravity="right" 
      android:background="@drawable/ic_launcher" 
      android:gravity="top|right" /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/song_list" 
     android:layout_width="fill_parent" 
     android:layout_height="500dp" > 
    </ListView> 

    <Space 
     android:id="@+id/blank_space" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center_horizontal" /> 

</LinearLayout> 
0

嘗試用相對佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/appColor" 
tools:context="SplashActivity"> 

<LinearLayout 
    android:id="@+id/buttonLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:orientation="vertical"> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_launcher" /> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_launcher" /> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_launcher" /> 
</LinearLayout> 

<ListView 
    android:id="@+id/listview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentRight="true" 
    android:layout_toRightOf="@+id/buttonLayout"> 

</ListView> 

</RelativeLayout>