android-如何在列表视图中设置按钮参数
我在程序中添加了按钮具有列表视图的页脚视图。现在我想设置按钮的参数并将按钮重力设置为垂直中心。我做了以下方式,但它不工作。如何实现这一点?android-如何在列表视图中设置按钮参数
btnMoreUpcomingExits = new Button(this);
btnMoreUpcomingExits.setText("More Upcoming Exits");
btnMoreUpcomingExits.setBackgroundResource(R.layout.moreupebtn_widget);
btnMoreUpcomingExits.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.WRAP_CONTENT, ListView.LayoutParams.WRAP_CONTENT));
btnMoreUpcomingExits.setTextColor(Color.WHITE);
btnMoreUpcomingExits.setTypeface(null, Typeface.BOLD);
btnMoreUpcomingExits.setGravity(Gravity.CENTER_HORIZONTAL);
btnMoreUpcomingExits.setOnClickListener(btnMoreUpcomingExitsListener);
getListView().addFooterView(btnMoreUpcomingExits);
setListAdapter(new UpcomingExitsResultsListViewAdapter(this));
您现在有
btnMoreUpcomingExits.setGravity(Gravity.CENTER_HORIZONTAL);
我认为这是一个疏忽,你的意思CENTER_VERTICAL?这将垂直对齐按钮内的文本,它应该已经在做,所以你的问题似乎令人困惑。你是否问如何垂直对齐按钮?如果是这样,您需要在父按钮上设置重力。
至于参数,你已经设置了布局参数。你还想做什么?你的目标应该是针对你的问题更加具体,以便识别你想要做的事情。
在这里重力的意义上,我想将按钮设置为“Center_Horizontal”(如layout_gravity)。在我的情况下,它的paarams被认为是fill_parent,现在我想将其设置为wrap_content。我想现在你会明白吗? – naresh 2012-07-11 12:49:25
对不起,我仍然不确定你在问什么。是否有可能创建一个图像来描述你想要的外观?这可能会解决任何混乱。如果您选择这样做,使用工具可能最适合制作图像。以下是一些线框图工具,可用于快速制作您想要的外观原型。 http://*.com/questions/929875/gui-design-tools-to-mock-up-iphone-android-applications – 2012-07-11 13:02:43
也请查看此链接:https://groups.google.com/forum/?fromgroups# !topic/android-developers/U5pW9b06ikM – Sats 2012-07-11 12:50:49
试试这个:
LinearLayout layout=new LinearLayout(getApplicationContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layout.setOrientation(LinearLayout.VERTICAL);
btnMoreUpcomingExits = new Button(this);
btnMoreUpcomingExits.setText("More Upcoming Exits");
btnMoreUpcomingExits.setBackgroundResource(R.layout.moreupebtn_widget);
btnMoreUpcomingExits.setLayoutParams(params);
btnMoreUpcomingExits.setTextColor(Color.WHITE);
btnMoreUpcomingExits.setTypeface(null, Typeface.BOLD);
btnMoreUpcomingExits.setGravity(Gravity.CENTER_HORIZONTAL);
layout.addView(btnMoreUpcomingExits);
btnMoreUpcomingExits.setOnClickListener(btnMoreUpcomingExitsListener);
getListView().addFooterView(btnMoreUpcomingExits);
setListAdapter(new UpcomingExitsResultsListViewAdapter(this));
它不工作我得到了这个异常07-11 18:23:52.301:我/ System.out(13207):错误来自WSResponse:java.lang.ClassCastException:android.widget.LinearLayout $ LayoutParams不能转换为android.widget.AbsListView $ LayoutParams – naresh 2012-07-11 12:55:57
不添加getListView()。addFooterView(btnMoreUpcomingExits);添加列表和按钮下的布局和设置按钮的参数,因为我已经做 – AkashG 2012-07-11 12:58:14
对不起,我没有得到。 – naresh 2012-07-11 13:03:44
您的列表视图是线性或相对布局下?线性布局下的 – AkashG 2012-07-11 12:45:30
。 – naresh 2012-07-11 12:46:27
你在列表视图中使用相对布局? – Ishtiaq 2012-07-11 12:54:08