我有想要填满整个屏幕的列表视图,列表视图中有四个项目。填充四个项目后,它在下面留下空白空间。您可以在屏幕截图中看到。它留下了空白区域。我想覆盖整个屏幕。
我想有这样的:
这是源代码
MainActivity.java。
public class MainActivity extends Activity {
ListView resultPane;
List<Taskinfo> list;
CustomAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultPane = (ListView) findViewById(R.id.mylist);
list = new ArrayList<Taskinfo>();
Resources res = getResources(); // resource handle
Drawable drawable = res.getDrawable(R.drawable.browse_home);
list.add(new Taskinfo("Browse", drawable));
drawable = res.getDrawable(R.drawable.jewelry);
list.add(new Taskinfo("Whats New", drawable));
drawable = res.getDrawable(R.drawable.show);
list.add(new Taskinfo("Upcoming Show", drawable));
drawable = res.getDrawable(R.drawable.contact);
list.add(new Taskinfo("Contact Us", drawable));
adapter = new CustomAdapter(this, list);
resultPane.setAdapter(adapter);
}
}
CustomAdapter.java
public class CustomAdapter extends BaseAdapter {
private Context context;
private List<Taskinfo> list;
public CustomAdapter(Context context, List<Taskinfo> list) {
this.context = context;
this.list = list;
}
public View getView(int index, View view, final ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.single_list_item, parent, false);
}
Taskinfo t = list.get(index);
RelativeLayout l = (RelativeLayout) view
.findViewById(R.id.testrelative);
l.setBackgroundDrawable(t.getImage());
TextView textView = (TextView) view.findViewById(R.id.title);
textView.setText(t.getName());
return view;
}
}
single_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/testrelative"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/browse_home"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="3dip" >
</LinearLayout>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:text=""
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
</RelativeLayout>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45sp"
android:id="@+id/llayout"
android:background="@drawable/navbar"
android:padding="3sp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Golden Stone"
android:textColor="@color/white"
android:textSize="20sp" >
</TextView>
</LinearLayout>
<ListView
android:id="@+id/mylist"
android:layout_width="match_parent"
android:layout_below="@id/llayout"
android:layout_height="match_parent" >
</ListView>
</RelativeLayout>