2014-10-19 46 views
0

我是Android新手,並遇到ListView控件問題。每當我添加一個ListView的觀點,我面臨着以下問題:ListView Alignment

  1. ListView控件那張寬度爲100%,100%的高度,我想補充的頂部按鍵並不能這樣做,因爲這。我想手動指定寬度,高度。

  2. ListView控件具有某種填充的啓用,我希望它是100%的寬度,但它看起來像它的90%

我該如何解決這些問題呢?我正在使用Eclipse。謝謝!

的ListView:

<ListView 
    android:id="@+id/listView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="0dp" > 
</ListView> 

行:

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rowTextView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp" android:textSize="12sp" > 
    </TextView> 

完成佈局:

<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="#000000" 

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.kb.kl.MainActivity" > 

<ListView 
    android:id="@+id/listView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

</ListView> 

</RelativeLayout> 
+0

您的ListView佈局不完整。請發佈完整的佈局。 – 2014-10-19 12:13:23

回答

1

使用android:layout_weight來防止listview佔用所有可用空間。例如:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/someButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:padding="0dp" /> 

</LinearLayout> 

至於填充的問題,我不知道你描述....是因爲你的rowTextView的10dp填充可能會造成的呢?

+0

謝謝,解決了第一個問題。我將10dp設置爲0dp,仍然是一樣的。看起來listview在所有方面都有一個邊距,例如當你進入android設置時,它不完全適合邊緣,例如,listview從1px x wise開始,我的像從10th開始 – user3578847 2014-10-19 12:55:41

+0

對於填充問題,你能發佈完整的佈局文件和使用它的活動的來源嗎? – mjp66 2014-10-19 13:01:37

+0

更新了我的問題,謝謝! – user3578847 2014-10-19 13:07:42

1

如果你想穿上列表視圖頂部的按鈕,你應該使用一些佈局像linearLayout一樣幫助你。這是指導。 http://developer.android.com/guide/topics/ui/layout/linear.html

至於填充ListView,我不認爲有這樣的設置。通常,在XML中有像divider/entries/dividerHeight這樣的設置。但它們都與填充無關。