简体   繁体   English

如何让我的ListView在Android中填满整个屏幕?

[英]How do I allow my ListView to fill the entire screen in Android?

I'm making a listview in android, and my listview doesn't fill the entire screen. 我在android中制作了一个listview,我的listview没有填满整个屏幕。 It has some remaining plain space below the listview (probably because i don't have enough items to fill the screen). 它在listview下面有一些剩余的空格(可能是因为我没有足够的项目来填充屏幕)。 I've searched for many solutions online, but none seem to be able to solve this problem. 我在网上搜索了很多解决方案,但似乎没有人能够解决这个问题。

Here is my layout: 这是我的布局:

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

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

 </ListView>


</LinearLayout>

Here is my item_layout.xml: 这是我的item_layout.xml:

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id= "@+id/ItemNameSales"
        android:layout_alignParentLeft="true"
        android:text="Item Name"
        android:textAppearance="?android:attr/textAppearanceLarge"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id= "@+id/ItemNameQty"
        android:layout_alignParentRight="true"
        android:text="Item Quantity"
        android:textAppearance="?android:attr/textAppearanceLarge"/>

</RelativeLayout>

你必须在dinamically改变它以适应intire屏幕!

list.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, CalculateHowYouNeedToFitScreen));

Your ListView is already fill entire screen problem is that you dont have have enaf items in list. 你的ListView已经填满整个屏幕问题是你没有列表中的enaf项目。 Another thing that you shoud do is to create holder class to prevant ListView loose list order.You can change dinamicly widht and height of item to fill screen but that is bad practices in coding 你要做的另一件事就是创建持有者类来提供ListView松散列表顺序。你可以改变项目的高度和填充屏幕的高度,但这是编码中的不良做法

   View itemView = convertView;
    ViewHolder holder;

    if (itemView == null) {

     itemView = getLayoutInflater().inflate(R.layout.YOURVIEW,parent,false);
     holder = new ViewHolder();
     itemView.setTag( holder );
    }else {
     holder = (ViewHolder) itemView.getTag();
    }
     SalesItemInformationLV iteminfo = item.get(position);

     holder.something = (TextView)itemView.findViewById(R.id.ItemNameSales);

     public class ViewHolder{

      public TextView something;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM