0

我正在尝试动态添加 ListView,但由于某种原因,它不允许我设置 ListView 的宽度。我想知道你们是否可以帮助我。

我正在尝试构建一个列设计(类似于 Plume)。这是最好的方法吗?

这是我所拥有的:

package com.reditr.column;

import java.util.HashMap;

import android.view.ViewGroup;
import android.widget.ListView;

import com.reditr.connection.Reddit;

public class ColumnManager {

//some pointers to important vars
private ViewGroup mContainer;
private Reddit mConnection;
private HashMap<String, Column> mColumns;

public ColumnManager(ViewGroup parent, Reddit connection) {

    mContainer = parent;
    mConnection = connection;   
    mColumns = new HashMap<String, Column>();

            //creates listview here
    mColumns.put("reditr", new Column("/r/reditr", null, mConnection, mContainer, "reditr", null));
    buildColumn(mColumns.get("reditr"));

            //.getColumnView() returns the ListView Object
    mContainer.addView(mColumns.get("reditr").getColumnView()); 
    mColumns.get("reditr").run();

    mColumns.put("gaming", new Column("/r/gaming", null, mConnection, mContainer, "gaming", null));
    buildColumn(mColumns.get("gaming"));
    mContainer.addView(mColumns.get("gaming").getColumnView()); 
    mColumns.get("gaming").run();


}

private void buildColumn(Column column) {

    ListView columnView = column.getColumnView();

    columnView.setMinimumWidth(400);
    columnView.setMinimumHeight(ViewGroup.LayoutParams.MATCH_PARENT);

}
}
4

1 回答 1

0

您可以使用LayoutParams在将 View 添加到其父级时设置其布局宽度和高度。将 LayoutParams 添加为addView(View, LayoutParams).

于 2013-04-08T15:31:27.217 回答