2012-07-31 65 views
2

嗨我已经创建了一个listActivity,其中包含一些数据行,并在屏幕的底部(不是列表)我已经把一个按钮。我的问题是,如果我的列表已满,因此需要滚动以便看到其他行,该按钮似乎是透明的并且与列表的最后一个元素重叠。所以它看起来并不令人愉快。您是否有任何建议解决这个问题?有没有办法让我的列表为底部按钮留下一些空间?我不想用footer view来实现它。我会发布xml文件,以便可以有更清晰的图片。ListActivity与底部按钮

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

    <DragNDrop.DragNDropListView 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_weight="1" > 
    </DragNDrop.DragNDropListView> 

    <Button 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:alpha="1" 
     android:drawableLeft="@drawable/back" 
     android:text="Return" /> 

</RelativeLayout> 

回答

2

试试这个

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

    <Button 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:alpha="1" 
     android:drawableLeft="@drawable/back" 
     android:text="Return" /> 

    <DragNDrop.DragNDropListView 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/btn" > 
    </DragNDrop.DragNDropListView> 

</RelativeLayout> 

在RelativeLayout的,元素放置在默认的左上角,有没有必要指定的目录

+0

ok我尝试了一切似乎正在工作,因为我想非常感谢大家的答案和时间 – Libathos 2012-07-31 08:20:56

1

最简单的方法是用orientation = verticalListView使用LinearLayoutlayout_weight = 1和按钮的下方的ListView。

1

把按钮在第一相对布局,然后设置属性

android:layout_above="@id/btn" 

列表视图。所以最后的元素不会被按钮发现,因为列表的高度是最大高度减去按钮高度。

1

更改XML如下图所示

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

<DragNDrop.DragNDropListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_above="@id/btn" 
    android:layout_marginBottom="50dp" 
    android:layout_weight="1" > 
</DragNDrop.DragNDropListView> 

<Button 
    android:id="@+id/btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:alpha="1" 
    android:drawableLeft="@drawable/back" 
    android:text="Return" /> 

</RelativeLayout> 
1

试试这个,这样你就可以在整个视图中获得10%的按钮,而列表视图和按钮的90%将不会与最后一个列表元素重叠。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:weightSum="100" > 

<ListView 
    android:id="@+id/android:list" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="90" > 
</ListView> 

<Button 
    android:id="@+id/btn" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="10" 
    android:text="Return" /> 

</LinearLayout>