Android在ListView和Adapter上方添加Button

时间:2015-02-28 13:05:37

标签: android listview layout android-listview

我有一个ListView,它从适配器获取它的数据,该适配器将2个TextView放入其中。我还有一个按钮,可以将内容添加到列表中 但是当我的Listview有很多项目时,它涵盖了Button:

enter image description here

我无法摆脱它!

以下是图片中活动的布局:

activity_default_color.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:padding="10dp" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <RelativeLayout
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">
            <com.software.shell.fab.ActionButton
                xmlns:fab="http://schemas.android.com/apk/res-auto"
                android:id="@+id/action_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:type="DEFAULT"
                fab:button_color="@color/fab_material_orange_500"
                fab:button_colorPressed="@color/fab_material_lime_900"
                fab:image="@drawable/fab_plus_icon"
                fab:image_size="24dp"
                fab:shadow_color="#757575"
                fab:shadow_radius="5.0dp"
                fab:shadow_xOffset="1dp"
                fab:shadow_yOffset="1dp"
                fab:show_animation="@anim/fab_roll_from_down"
                fab:hide_animation="@anim/fab_roll_to_down"
                android:layout_gravity="right|bottom"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"/>
        </RelativeLayout>
    </FrameLayout>

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <RelativeLayout
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">
                <ListView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/colorList"
                    android:layout_weight="1" />
            </RelativeLayout>
    </FrameLayout>

</FrameLayout>

这是我的适配器布局: 的 myAdapter_item.xml

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

    <TextView
        android:id="@android:id/text1"
        android:layout_width="1000dp" <!-- I now it's ugly but match_parent doesn't work -->
        android:layout_height="30dp"
        android:textSize="20dp"
        android:layout_marginTop="1dp"/>

    <TextView
        android:id="@android:id/text2"
        android:layout_width="1000dp" <!-- I now it's ugly but match_parent doesn't work -->
        android:layout_height="20dp"
        android:layout_marginTop="0dp"/>

</LinearLayout>

我怎样才能在绝对前方获得按钮

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,但使用下面的代码解决了..

使用列表视图和浮动操作按钮布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">

    <ListView
        android:id="@+id/provider_service_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#999999"
        >

        </ListView>
    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dp"
        android:src="@drawable/ic_action_add_icon"
        fab:fab_colorNormal="#FF0000"
        fab:fab_colorPressed="#DF0101"
        fab:fab_colorRipple="@color/accent"
        fab:fab_shadow="true"
        fab:fab_type="normal"




        />


</FrameLayout>

现在无论你在适配器中使用什么,都没有问题。

感谢https://github.com/makovkastar/FloatingActionButton

在你班上使用这个

ListView provider_service_list = (ListView)findViewById(R.id.provider_service_list);
FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);

    fab.setShadow(true);        
     fab.attachToListView(provider_service_list);

如果您的问题没有解决,请告诉我。

相关问题