我尝试在活动中列出一个RecyclerView,但这是不可能的
这是MainActivity
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
当我将许多视图添加到一个活动中时,它不能滚动:'(
有人能帮我解决这个问题吗?
给我一些关键字或任何图腾,所以非常感谢。。。
我只想做一个类似谷歌商店特色列表的布局,像这样的IMAGE
发布于 2015-04-10 13:41:08
使用RelativeLayout作为根,并将按钮上的RelativeLayout.LayoutParams设置为与底部对齐。你也可以用FrameLayout (边际和重力)来实现它,但据我所知,它在姜饼上工作得不好。
发布于 2015-04-10 13:42:23
如果要启用滚动,请使用ScrollView作为layoutMain。默认情况下,它有一个LinearLayout。因此,我建议使用布局xml来轻松完成这项工作。
https://stackoverflow.com/questions/29553763
复制相似问题