2016-02-11 11 views
7

Tôi đang phát triển một ứng dụng Android hoạt động chủ yếu với listview. Nhưng tôi gặp sự cố khi sử dụng Floating Action Button cùng với Long ListView. Vấn đề của tôi là như dưới đây.Làm cách nào để đặt vị trí cố định cho nút thao tác nổi phía trên chế độ xem danh sách rất dài trong Android?

Khi chế độ xem danh sách chỉ có một vài mục. Floating item có thể được nhìn thấy.

Đây là ảnh chụp màn hình.

enter image description here

Như bạn thấy ở trên, Floating Action Button vẫn có thể được seen.But khi ListView có rất nhiều mặt hàng và trở thành quá mức vào màn hình, Floating Action Button không thể được nhìn thấy.

Đây là ảnh chụp màn hình của Long Listview

enter image description here

Đối với ảnh chụp màn hình thứ hai, nó không thể là scrolled down nữa.

Điều tôi muốn đạt được là, tôi muốn đáy nổi luôn ở dưới cùng bên phải của màn hình phía trên Listview. Giống như vị trí cố định trong HTMLCSS.

Tôi muốn Floating Action Button luôn ở đây bất kể có bao cao các Listview

enter image description here

Đây là file layout của tôi

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
     <ListView 
      android:dividerHeight="@dimen/list_item_divider_height" 
      android:padding="@dimen/list_padding" 
      android:divider="@color/whitesmoke" 
      android:id="@+id/listview_podcast_list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"></ListView> 

     <TextView 
      android:textSize="17dp" 
      android:textStyle="bold" 
      android:textColor="@color/black" 
      android:textAlignment="center" 
      android:id="@+id/tf_no_records" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/stop_podcast_button" 
     android:background="@color/colorPrimary" 
     android:src="@android:drawable/ic_dialog_email" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end"/> 
</LinearLayout> 

Vì vậy, hãy làm sao tôi có thể sửa mã của tôi thành ach ieve nó. Làm ơn giúp tôi với. Cảm ơn.

Trả lời

14

Thử sử dụng RelativeLayout thay vì LinearLayout. Và đối với FloatingActionButton thêm thuộc tính như thế này,

android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentRight="true" 
    android:layout_gravity="end|bottom" 
+0

Cảm ơn. Nó hoạt động hoàn hảo. –

+0

Tôi sẽ upvote câu trả lời sớm, –

+0

Vui mừng nó đã giúp :) – ajantha

0

Không đặt nút trong Bố cục tuyến tính.

Sử dụng

FrameLayout vì vậy bạn có thể đặt xem trên đầu trang của người khác

4

Hãy thử sử dụng với CoordinatorLayout

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="listview.anubavam.com.listview.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" > 

     </android.support.v7.widget.Toolbar> 


    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_main" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_menu_camera" /> 

</android.support.design.widget.CoordinatorLayout> 
Các vấn đề liên quan