0
public class Dues extends Activity {
static final String[] alphabets = new String[] {
"A", "B", "C", "D"};
static final String[] alphabets1 = new String[] {
"E", "F", "G", "H"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dues);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, alphabets);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, alphabets1);
RelativeLayout relativeLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams relativeLayoutParams = new
RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
GridView gridView= new GridView(this);
gridView.setLayoutParams(new
GridView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
gridView.setNumColumns(4);
gridView.setAdapter(adapter);
Drawable myIcon = getResources().getDrawable(R.drawable.bg);
gridView.setBackground(myIcon);
GridView gridView1 = new GridView(this);
gridView1.setLayoutParams(new
GridView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
gridView1.setNumColumns(4);
gridView1.setAdapter(adapter);
Drawable myIcon = getResources().getDrawable(R.drawable.bg);
gridView1.setBackground(myIcon);
}
}
因此,此代碼創建2個gridview,但其重疊。請幫幫我。 ABCD和EFGH都相互重疊。 這樣我想添加多個GridView使用滾動查看。 任何人都可以幫助我這個請。 我希望它是可見的一個在另一個之下。如何以編程方式創建多個gridview
gridview的數量是動態的,也沒有固定的數量,因此我希望它以編程方式創建,而不是通過xml文件。 也我希望它是綠色透明,所以任何人都可以幫助我也
噢好吧!,非常感謝。我做了wrap_content,但是然後gridview不可見 –
你能幫助它的代碼嗎? –
按照我說的一步一步來做。你不能使用ScrollView來實現這一點,你必須使用NestedScrollView – Ricardo