Java 填充屏幕时,对话框不可滚动
我正在开发一个android应用程序。在其中一个活动中,我有一个服务列表,我希望用户对每个服务进行评分。服务位于Java 填充屏幕时,对话框不可滚动,java,android,dialog,android-alertdialog,Java,Android,Dialog,Android Alertdialog,我正在开发一个android应用程序。在其中一个活动中,我有一个服务列表,我希望用户对每个服务进行评分。服务位于表格布局中(每个服务位于其自己的行中)。在行的末尾,我有一个Rate按钮。当用户单击它时,会弹出一个对话框,对话框底部有分级栏、编辑视图和两个按钮。我的问题是,当按钮上弹出键盘,用户在EditText框中写几行时,关键字会隐藏按钮。因此,用户不能按按钮,用户需要最小化键盘才能看到按钮 现在,我看到了一些关于这个主题的问题,但它们都有xml解决方案。在我的例子中,对话框都是代码,在这种情
表格布局中(每个服务位于其自己的行中)。在行的末尾,我有一个Rate按钮
。当用户单击它时,会弹出一个对话框
,对话框底部有分级栏
、编辑视图
和两个按钮。我的问题是,当按钮上弹出键盘,用户在EditText
框中写几行时,关键字会隐藏按钮。因此,用户不能按按钮,用户需要最小化键盘才能看到按钮
现在,我看到了一些关于这个主题的问题,但它们都有xml
解决方案。在我的例子中,对话框都是代码,在这种情况下我不使用xml布局。(我不确定这是否正确,但它符合我的需要)
这是一张图片
这是对话框的代码。这是单击“速率”按钮时发生的情况。
有什么想法吗
e.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
boolean same = false;
TableRow row = new TableRow(QAListActivity.this);
RatingBar ratingBar = new RatingBar(QAListActivity.this);;
Dialog rankDialog = new Dialog(QAListActivity.this);
rankDialog.setContentView(R.layout.qa_rate);
rankDialog.setCancelable(true);
rankDialog.setCanceledOnTouchOutside(true);
TableLayout table1 = new TableLayout(QAListActivity.this);
ArrayList<RatingBar> ratingBars = new ArrayList<RatingBar>();
EditText comment = new EditText(QAListActivity.this);
for(int z = 0; z < tour.QAList.size(); z++){
if(tour.QAList.get(z).getServiceType().equalsIgnoreCase(tour.voucherList.get(position).getServiceType())){
rankDialog.setTitle("Rate " + tour.voucherList.get(position).getDescription());
same = true;
row = new TableRow(QAListActivity.this);
TextView text = new TextView(QAListActivity.this);
ratingBar = new RatingBar(QAListActivity.this);
ratingBars.add(ratingBar);
text.setText(tour.QAList.get(z).getQualityDesc());
text.setTextSize(20);
text.setHeight(40);
text.setGravity(Gravity.CENTER_VERTICAL);
row.addView(text);
row.addView(ratingBar);
row.setGravity(Gravity.CENTER);
table1.addView(row,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tour.voucherList.get(position).voucher_rating.add(tour.QAList.get(z));
}
}
if(same){
String type = tour.voucherList.get(position).getServiceType();
if (type.equalsIgnoreCase("CNV")){
String[] qa_bus = {"Bus Make","Bus Year","Number of Seats","Bus Company","Bathroom on Bus?","Driver's Name",
"Driver speaks English","Helpfulness of driver (on/off bus)","Were there Gate1 signs on the bus?"};
TableLayout table_bus = new TableLayout(QAListActivity.this);
for(int count = 0; count < qa_bus.length; count++){
TableRow row_make = new TableRow(QAListActivity.this);
EditText make = new EditText(QAListActivity.this);
make.setHint(qa_bus[count]);
make.setWidth(table.getWidth()/2+50);
row_make.addView(make);
row_make.setGravity(Gravity.CENTER);
table_bus.addView(row_make, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT));
}
table1.addView(table_bus);
}
else{
TableLayout table_comment = new TableLayout(QAListActivity.this);
TableRow row_comment = new TableRow(QAListActivity.this);
comment = new EditText(QAListActivity.this);
comment.setHint("Remarks");
comment.setWidth(table.getWidth()/2+50);
row_comment.addView(comment);
row_comment.setGravity(Gravity.CENTER);
table_comment.addView(row_comment, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT));
table1.addView(table_comment);
}
TableLayout table_buttons = new TableLayout(QAListActivity.this);
TableRow save_row = new TableRow(QAListActivity.this);
Button save = new Button(QAListActivity.this);
save.setText("Save");
save_row.addView(save);
save_row.setGravity(Gravity.CENTER);
final Dialog rankDialogTemp = rankDialog;
final ArrayList<RatingBar> ratingBarsTemp = ratingBars;
final EditText remarksTemp = comment;
save.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
for(int xx = 0; xx < ratingBarsTemp.size(); xx++){
Log.d("ratingBar", "" + ratingBarsTemp.get(xx).getRating());
tour.voucherList.get(position).voucher_rating.get(xx).setRating(ratingBarsTemp.get(xx).getRating());
}
tour.voucherList.get(position).setQAcompleted(true);
tour.voucherList.get(position).setRemarks(remarksTemp.getText().toString());
rowTemp.setBackgroundColor(Color.GREEN);
getInfo.saveOfflineData(QAListActivity.this, new Gson().toJson(TourListActivity.TourList), DateFormat.getDateTimeInstance().format(new Date()));
rankDialogTemp.dismiss();
}
});
Button back = new Button(QAListActivity.this);
back.setText("Back");
save_row.addView(back);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
rankDialogTemp.dismiss();
}
});
table_buttons.addView(save_row);
table1.addView(table_buttons);
}
rankDialog.addContentView(table1, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
//now that the dialog is set up, it's time to show it
rankDialog.show();
}
});
也许可以玩WindowsofInputMode
或者将按钮放在滚动视图中,以便用户可以向下滚动到它。但是按钮是对话框中表格的一部分。按钮位于表格的最后一行。将整个表格置于滚动视图中。如果不想定义xml布局,可以动态执行此操作。尽管我强烈建议您切换到xml布局,但它们更易于使用。你能给我看看你的密码吗?在何处将表添加到视图?是否看到代码?任何人该对话框位于scrollview中。您应该定义一个布局,将所有内容放入一个对话框中。然后在运行时将布局膨胀到对话框中。您可以将xml布局添加到一个对话框中吗?该对话框已在scrollview中
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/qa_rate"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="@+id/rating"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:stretchColumns="*"
android:paddingRight="5dp"
android:orientation="vertical" >
</TableLayout >
</ScrollView>