In Android, how can I set a ListView item's height and width?

I want to create an interface that has one or two listviews that ultimately span the entire screen with two rows. How can I change their height so that they take up 50% of the screen, vertically?

If it's along the same lines, I'd love to know how to do this regardless of orientation.

With regards to width; let us say I have two listviews, each with one row. They span the entire screen as described above. The lower listview has two clickable items within it that each take up 50% of the screen space, horizontally.

Is that possible? If so, how?


Hi the following code will use full to create an interface that has one or two listviews that ultimately span the entire screen with two rows. The Java file is as follows,

public class DoubleListView extends Activity {
    ListView listView,listView2;
    String[] titles = {"List 1 title1","List 1 title2","List 1 title3","List 1 title4","List 1 title5","List 1 title6","List 1 title7","List 1 title8","List 1 title9"};
    String[] titles2 = {"List 2 title1","List 2 title2","List 2 title3","List 2 title4","List 2 title5","List 2 title6","List 2 title7","List 2 title8","List 2 title9"};
    WindowManager wm;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
        int height = wm.getDefaultDisplay().getHeight();

        listView = new ListView(this);
        listView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,height/2-15));
        listView.setAdapter(new CustomListAdapetr(this, titles));

        listView2 = new ListView(this);
        listView2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,height/2));
        listView2.setAdapter(new CustomListAdapetr(this, titles2));


    public class CustomListAdapetr extends BaseAdapter{

        private Context mContext;
        private String[] list;

        public CustomListAdapetr(Context context, String[] titles) {
            mContext = context;
            list = titles;

        public int getCount() {
            // TODO Auto-generated method stub
            return list.length;

        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return list[position];

        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;

        public View getView(int position, View convertView, ViewGroup parent) {
            CustomView cv;
            if (convertView == null) {
                cv = new CustomView(mContext,""+list[position]);
            else {
                    cv = (CustomView) convertView;


            return cv;


    private class CustomView extends LinearLayout {
        public CustomView(Context context, String itemName) {
            // Here we build the child views in code. They could also have
            // been specified in an XML file.

            mTitle = new TextView(context);


            addView(mTitle, new LinearLayout.LayoutParams(200, LayoutParams.WRAP_CONTENT));

        /**         * Convenience method to set the title of a SpeechView         */
        public void setTitle(String title) {
        /**         * Convenience method to set the dialogue of a SpeechView         */

        private TextView mTitle;



And the xml file is,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""


Try this to get your desired interface.

Need Your Help

How do I allow safely and inexpensively allow images on my site?

ruby-on-rails security image xss markdown

I have developed a social networking site for gardeners website, and am interested in giving users the ability to add images to their "tweets".

Include HTMLpurifier with Zend_Loader

php zend-framework htmlpurifier

I want to use the HTMLpurifier in combination with the Zend Framework. I would love to load the Class and its files with the Zend_Loader. How would you include it? Would you just use the HTMLPurifier.