【发布时间】:2015-04-10 05:01:50
【问题描述】:
我尝试将 RecyclerView 列出到 Activity 中,但它不可能
这是主活动
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layoutMain = new LinearLayout(this);
layoutMain.setOrientation(LinearLayout.VERTICAL);
setContentView(layoutMain);
LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RecyclerView recList = new RecyclerView(this);
recList.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(LinearLayoutManager.VERTICAL);
recList.setLayoutManager(llm);
custom_button buttons = new custom_button(this, "button");
Button buttons2 = new Button(this);
buttons2.setText("button2");
ContactAdapter ca = new ContactAdapter(createList(3));
recList.setAdapter(ca);
layoutMain.addView(buttons); // this is custom button
layoutMain.addView(recList); // this is RecyclerView but it
layoutMain.addView(buttons2);
}
完成后这是image
当我将许多视图添加到一个活动中时,它无法滚动:'(
谁能帮我解决这个问题
给我一些关键字或任何 TUT,非常感谢。 . .
p/s : 我只想制作一个像这样的谷歌商店特色列表的布局 IMAGE
【问题讨论】:
-
使用相对布局。添加带有参数的按钮作为 alignParent 顶部按钮 2 作为 alignParent 底部和带有布局参数的回收器视图,其中按钮 2 上方和按钮下方。这将为您提供所需的布局。考虑给按钮起有意义的名字,并通过java命名约定(custom_button?)
-
` ALIGN_PARENT_TOP CENTER_IN_PARENT ALIGN_PARENT_BOTTOM ` :'( 不工作你能帮我修复这个愚蠢的代码吗
标签: android listview gridview android-listview