Android使对话框可滚动

标签 android layout dialog scrollview scrollable

当用户单击按钮时,我会显示一个对话框。当对话框出现并且您单击 EditText 输入一些文本时,您将看不到底部按钮(和最低的 EditText)。所以你必须按下键盘,然后选择按钮或EditText。我搜索了一段时间的答案,但找不到。

那么:如何使我的对话框可滚动?显然我的代码不能解决问题:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical"
    android:scrollbars="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true">

<EditText         
   android:id="@+id/addKlantNaam"
   android:textSize="20sp"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:hint="@string/klantNaam" 
   />

<EditText         
   android:id="@+id/addKlantLocatie"
   android:textSize="20sp"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:hint="@string/klantLocatie" 
   />

<TextView
    android:id="@+id/scheidenDoorKomma"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:text="@string/scheidenDoorKomma"/>

<EditText         
   android:id="@+id/addFabrieken"
   android:textSize="20sp"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:hint="@string/fabrieken" 
   />

 <EditText        
   android:id="@+id/addMachines"
   android:textSize="20sp"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:hint="@string/machines" 
   />

 <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" >

    <Button
        android:id="@+id/dialogAnnuleren"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:text="@string/annuleren"
        android:textSize="22sp" />

    <Button
        android:id="@+id/dialogToevoegen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"   
        android:layout_toRightOf="@+id/dialogAnnuleren"     
        android:textSize="22sp"
        android:text="@string/toevoegen"/>
  </RelativeLayout>

</LinearLayout>

这就是我调用对话框的方式:

btnAdd.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View arg0) {

            // custom dialog
            dialog = new Dialog(context);
            dialog.setContentView(R.layout.addklant_layout);
            dialog.setTitle("Klant toevoegen");

            Button BTNannuleren = (Button) dialog.findViewById(R.id.dialogAnnuleren);
            // if button is clicked, close the custom dialog
            BTNannuleren.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            Button BTNtoevoegen = (Button) dialog.findViewById(R.id.dialogToevoegen);
            // if button is clicked, close the custom dialog
            BTNtoevoegen.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    StoreKlantInDatabase task = new StoreKlantInDatabase();     
                        task.execute(urlInsertKlant);
                        dialog.dismiss();
                    }
            });      
            dialog.show();
      }
    });

谁能帮帮我?

最佳答案

您所问的指南是 can be found here .如你看到的。有多种方法可以实现您的要求。

除此之外,您可以考虑更改键盘上“Enter”按钮的默认操作以选择下一个 EditText 并最终在完成后提交表单 (read up about it here):

android:imeOptions="actionDone"

关于Android使对话框可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19109576/

相关文章:

c# - 将属性绑定(bind)到 Android 中的 mvxBindableListView

android - 如何为 SuperSLiM 库编译 JAR?

angular - 禁止在 Angular Material 对话框区域外单击以关闭对话框(使用 Angular 版本 4.0+)

ruby-on-rails - 为不同的布局使用不同的 CSS

android - 如何在多个 Activity 中显示相同的对话框?

delphi - 如何在默认 Unicode 的 Delphi XE 应用程序的消息对话框中使用 ASCII 艺术符号

android - 尝试在 Android CallLog.Calls 上获取日期时出错

Android TextToSpeech.speak 在 onActivityResult 中不起作用

android - 如果我对不同布局中的多个小部件使用相同的 ID 会怎样?

android - 如何动态管理相对布局中的控件?