Custom Listview occupying 100% of the screen

Asked

Viewed 605 times

1

I created a Custom Listview with some items but as you can see in the image below is an "empty space" on the screen.

I would like to know how to make the items occupy all the remaining space on the screen.

inserir a descrição da imagem aqui

Menu code.java:

public class Menu extends Activity{

private List<MenuItensAndIcons> menuitens = new ArrayList<MenuItensAndIcons>();

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.menulistview);

    CriandoItensMenu();
    CriandoListView();

    final UsuarioLogado usuariologado = (UsuarioLogado) getApplicationContext();

    getActionBar().setTitle(usuariologado.getUsuariologado());
    getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

    }



private void CriandoItensMenu() {

    menuitens.add(new MenuItensAndIcons("Cadastrar", R.drawable.add));
    menuitens.add(new MenuItensAndIcons("Meus Cadastros", R.drawable.consulta));
    menuitens.add(new MenuItensAndIcons("Perfil", R.drawable.neutro));
    menuitens.add(new MenuItensAndIcons("Mapa", R.drawable.mapa));
    menuitens.add(new MenuItensAndIcons("Consulta Avançada", R.drawable.consulta));

}

private void CriandoListView() {

    ArrayAdapter<MenuItensAndIcons> arrayadapter = new MyListAdapter();
    ListView listamenu = (ListView)findViewById(R.id.menulist);
    listamenu.setAdapter(arrayadapter);
}

private class MyListAdapter extends ArrayAdapter<MenuItensAndIcons>{
    public MyListAdapter(){

        super(Menu.this, R.layout.item_view, menuitens);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View itemview = convertView;

        if(itemview == null){
            itemview = getLayoutInflater().inflate(R.layout.item_view, parent, false);

        }

        //achar o item especifico

        MenuItensAndIcons itematual = menuitens.get(position);

        //preenche os dados do listview

        ImageView imageview = (ImageView)itemview.findViewById(R.id.ItemIcon);
        imageview.setImageResource(itematual.getIconeMenu());

        TextView Textitem = (TextView)itemview.findViewById(R.id.item_TextItem);
        Textitem.setText(""+itematual.getNomeMenu());

        return itemview;
    }


}

Code for menulistview.xml:

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

    <ListView
        android:id="@+id/menulist"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>

</LinearLayout>

item_view.xml code:

<?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" >

    <ImageView
        android:id="@+id/ItemIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/add" />

    <TextView
        android:id="@+id/item_TextItem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/ItemIcon"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="15dp"
        android:layout_toRightOf="@+id/ItemIcon"
        android:text="Text Aqui"
        android:textColor="@android:color/white" />

</RelativeLayout>
  • Any special reason for being a Listview? This.information comes from some server?

  • I had created a menu with Imageviews, but with Listview it was more "pleasant"

1 answer

0


Hello!

The only solution that comes to mind is to increase the size of the ballot. However, with a little research I found a similar case and that might work for you!

Go to your Androidmanifest.xml file and add the following code:

 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

I hope it helps!

(Reference)

  • Thank you, I’ll test it here!

  • No problem! if it does not work let me know and we will try to find another solution :)

  • The code didn’t work, but I increased the size of each item as you had commented and now it’s perfect! vlw same guy!

  • Glad to hear it! Gina brother, good luck!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.