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.
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?
– rsicarelli
I had created a menu with Imageviews, but with Listview it was more "pleasant"
– Mantir