How to create a overlay layout upon a listview

后端 未结 2 1877
名媛妹妹
名媛妹妹 2021-02-15 16:41

I have a listview that will be filled with AsyncTask and at the bottom edge of the app I need to show a fixed overlay layout like this:

相关标签:
2条回答
  • 2021-02-15 17:01

    Change the parent layout to RelativeLayout or FrameLayout and position the fixed view at the same level of the ListView (but after the ListView)

    Something like:

    ---> RelativeLayout
        --> ListView
        --> Any view as the fixed view
    

    You can then align the fixed view to the bottom of the wrapping RelativeLayout

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
       <ListView
           android:id="@+id/list"
           android:layout_width="match_parent"
           android:layout_height="wrap_content" />
    
       <!-- Here you should position the fixed view  -->
    </RelativeLayout>
    
    0 讨论(0)
  • 2021-02-15 17:17

    As Daniel has suggested, use a RelativeLayout because it allows stacking of components(same with FrameLayout and SurfaceView). The following code will give you the layout you are looking for:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    <RelativeLayout
       android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/transparentBlack"
        android:layout_alignParentBottom="true" >
    
       <TextView
           android:id="@+id/textView2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignBottom="@+id/textView1"
           android:layout_alignParentRight="true"
           android:layout_marginRight="20dp"
           android:text="Medium Text"
           android:textColor="@color/white"
           android:textAppearance="?android:attr/textAppearanceMedium" />
    
       <TextView
           android:id="@+id/textView1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentLeft="true"
           android:layout_centerVertical="true"
           android:layout_marginLeft="40dp"
           android:text="Large Text"
           android:textAppearance="?android:attr/textAppearanceLarge"
           android:textColor="@color/white" />
    
       </RelativeLayout>
    
    </RelativeLayout>
    

    In the code above, the color hex values used for transparentBlack is #95000000 and white is #ffffff.

    Here is an excellent tutorial on the basics of UI design in android: Android User Interface Design: Layout Basics.

    0 讨论(0)
提交回复
热议问题