Listview not filling its parent
I have faced following problem:
I'm trying to implement a navigation drawer with subheadings like the one
in gmail app and one another app:
As you can see, I have higlighted that there are no dividers at the end of
each list
SO I have taken an implementation with subheadings from stack overlfow and
I have ended up with something like this:
As you know, navigation drawer uses listview and the reason why divider
is there is because subheading is also a list item so setting option
footerDividerEnabled to false doesn't solve the problem.
So my next implementaiton was to put View which will contatin subheading
and listview and then added to navigation-drawer's listview.
Here is my source code of MainActivity:
package com.myphun.radio;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import com.example.androidradio.R;
import com.myphun.ui.adapters.ListViewAdapter;
import com.myphun.ui.components.SlidingMenuLayout;
public class MainActivity extends ActionBarActivity
{
private SlidingMenuLayout mSlidingMenuLayout;
private ListView leftDrawerList;
private ListViewAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSlidingMenuLayout = (SlidingMenuLayout)
findViewById(R.id.main_sliding_menu);
leftDrawerList = (ListView) findViewById(R.id.left_drawer_list);
ViewArrayAdapter viewArrayAdapter = new ViewArrayAdapter(this);
View generic_drawer_view = View.inflate(this,
R.layout.sliding_menu_general_section_layout, null);
viewArrayAdapter.add(generic_drawer_view);
ListView genericCategoriesListView = (ListView)
generic_drawer_view.findViewById(R.id.general_drawer_list);
mAdapter = new ListViewAdapter(this);
mAdapter.addItem("Mercury", R.drawable.mercury);
mAdapter.addItem("Venus", R.drawable.venus);
mAdapter.addItem("Earth", R.drawable.earth);
mAdapter.addItem("Mars", R.drawable.mars);
mAdapter.addItem("Neptune", R.drawable.neptune);
mAdapter.addItem("Saturn", R.drawable.saturn);
mAdapter.addItem("Uranus", R.drawable.uranus);
mAdapter.addItem("Jupiter", R.drawable.jupiter);
genericCategoriesListView.setAdapter(mAdapter);
leftDrawerList.setAdapter(viewArrayAdapter);
}
}
class ViewArrayAdapter extends ArrayAdapter<View>
{
public ViewArrayAdapter(Context context)
{
super(context, 0, new ArrayList<View>());
}
public ViewArrayAdapter(Context context, List<View> viewsList)
{
super(context, 0, viewsList);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
return getItem(position);
}
}
Main Activity XML:
<com.myphun.ui.components.SlidingMenuLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_sliding_menu"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView122"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</FrameLayout>
<!-- The navigation drawer -->
<ListView
android:id="@+id/left_drawer_list"
android:layout_width="275dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#444444"
android:choiceMode="singleChoice"
android:divider="#555555"
android:dividerHeight="0dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false" />
</com.myphun.ui.components.SlidingMenuLayout>
Custom view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/general_drawer_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/general_drawer_header"
android:layout_width="match_parent"
android:layout_height="62dp"
android:background="@drawable/list_selector"
android:gravity="bottom"
android:paddingBottom="5dp"
android:paddingRight="16dp"
android:text="Planets"
android:textColor="#FFFFFF"
android:textSize="25sp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ffffff" />
<ListView
android:id="@+id/general_drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EE444444"
android:choiceMode="singleChoice"
android:divider="#555555"
android:dividerHeight="1dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false" />
</LinearLayout>
But for some reason, listview doesn't fill entire screen:
I've tried many combination of xml_atributes (i.e. match_parent,
wrap_content, fill_parent) and the only one which works is when you set
ListView layout_height manually (i.e. layout_height ="625dp").
SO the question is: What I'am doing wrong ? How can I achieve desire
result ? Why is listview not expanding ?
No comments:
Post a Comment