Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to set a ListView at the bottom of a NavigationDrawer?

FedericoNavarreteFedericoNavarrete SVMember ✭✭✭
edited July 2018 in Xamarin.Android

I'm developing an app and I have an issue that I cannot a way of displaying the ListView at the bottom of the DrawerLayout, this is my code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minWidth="25px"
        android:minHeight="25px">
        <android.webkit.WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/webView" />
    </LinearLayout>
    <ListView
        android:id="@+id/navList"
        android:layout_width="180dp"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
        android:layout_gravity="left|start"
        android:background="#ffffff" />
</android.support.v4.widget.DrawerLayout>

This is how currently looks like:

I tried setting the ListView inside of a RelativeLayout and it didn't work at all (https://stackoverflow.com/a/51340119/2889347). This is what happens:

Also, I tried to set an ImageView too just to create some space, but in both cases the code broke the code.

This is what I'm trying to do:

Does anyone have any idea? Thanks.

Best Answer

Answers

  • robbitrobbit CNMember Xamurai

    Hi @FedericoNavarrete

    You can change your ListView to fragment:

    <fragment
        android:name="your package name.BlankFragment"
        android:layout_width="180dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"/>
    

    And in your BlankFragment's layout, you can use this to set the ListView at the bottom of NavigationDrawer:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="180dp"
        android:layout_height="match_parent"
        android:background="#e00808"
        tools:context=".BlankFragment">
    
        <!-- TODO: Update blank fragment layout -->
    
        <ListView
            android:id="@+id/navList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:choiceMode="singleChoice"
            android:layout_alignParentBottom="true"
            android:background="#ffffff" />
    
    </RelativeLayout>
    
  • FedericoNavarreteFedericoNavarrete SVMember ✭✭✭
    edited July 2018

    Hi @robbit after I added your code and I added the missing class:

    public class BlankFragment : Fragment
    {
        public BlankFragment()
        {
        }
    
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Inflate the layout for this fragment
            return inflater.Inflate(Resource.Layout.BlankFragment, container, false);
        }
    }
    

    I got exactly the same result:

  • robbitrobbit CNMember Xamurai

    Unable to instantiate fragment tk.supernova.tmtimer.tk.supernova.tmtimer.BlankFragment: make sure class name exists, is public, and has an empty constructor that is public

    Can you show your BlankFragment class?

  • FedericoNavarreteFedericoNavarrete SVMember ✭✭✭
    Hi @robbit , I updated my answer.
Sign In or Register to comment.