Android 要在listview中添加两个浮动按钮吗
我正在开发一个应用程序,我想在其中添加两个浮动按钮,比如google+ 因为我用的是 但实际上它只对一个按钮起作用,如果我添加了另一个按钮,那么添加的按钮不起作用,这意味着当滚动列表视图时,按钮没有消失 我尝试了以下代码,但没有工作Android 要在listview中添加两个浮动按钮吗,android,google-plus,imagebutton,floating,Android,Google Plus,Imagebutton,Floating,我正在开发一个应用程序,我想在其中添加两个浮动按钮,比如google+ 因为我用的是 但实际上它只对一个按钮起作用,如果我添加了另一个按钮,那么添加的按钮不起作用,这意味着当滚动列表视图时,按钮没有消失 我尝试了以下代码,但没有工作 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.acti
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FloatingActionButton floatingActionButton1 = (FloatingActionButton) findViewById(R.id.button_floating_action1);
FloatingActionButton floatingActionButton2 = (FloatingActionButton) findViewById(R.id.button_floating_action2);
floatingActionButton1.attachToListView(getListView());
floatingActionButton2.attachToListView(getListView());
ListAdapter listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
getResources().getStringArray(R.array.planets));
getListView().setAdapter(listAdapter);
}
非常感谢您的帮助。通过查找库代码
public void attachToListView(@NonNull AbsListView listView, ScrollDirectionListener listener) {
AbsListViewScrollDetectorImpl scrollDetector = new AbsListViewScrollDetectorImpl();
scrollDetector.setListener(listener);
scrollDetector.setListView(listView);
scrollDetector.setScrollThreshold(mScrollThreshold);
listView.setOnScrollListener(scrollDetector);
}
似乎它将setOnScrollListener设置为listview,对于单个listview,它只能有一个实例
所以,在您挖掘并使用库项目之前,它可能不起作用
另一种选择是使用浮动操作按钮弹出窗口,就像在这个应用程序中一样
对于弹出窗口的反弹效果,您可以使用来自facebook的很棒的反弹库
你也可以试试这个
List<Widget> float_buttons() {
List button_list = List<Widget>();
int i = 0;
List names = ['first', 'second', 'third', 'fourth', 'fifth'];
List P_type = [1,0,1,1,0];
for (i = 0; i < 5; i++) {
button_list.add(
FloatingActionButton.extended(onPressed: (){}, label: Text(names[i]), icon: P_type[i]==1?Icon(Icons.star):Icon(Icons.panorama),)
);
button_list.add(
SizedBox(width: 10,)
);
}
return button_list;
}
你可以通过按你的晶圆厂来打开一个里面有两个按钮的对话框。@DerGolem:我不明白你到底建议我做什么。如果你有任何解决方案或代码,请告诉我你可以用一个晶圆厂来打开一个对话框。然后,在对话框中,您可以从2个不同的按钮或更多按钮中进行选择。我没有代码,只是关于如何处理问题的想法。
Expanded(child: ListView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.all(20.0),
children: [Container(
child: Row(
children: float_buttons(),
),
)],
))