<small id='ZaRLy'></small><noframes id='ZaRLy'>

  • <legend id='ZaRLy'><style id='ZaRLy'><dir id='ZaRLy'><q id='ZaRLy'></q></dir></style></legend>

        <i id='ZaRLy'><tr id='ZaRLy'><dt id='ZaRLy'><q id='ZaRLy'><span id='ZaRLy'><b id='ZaRLy'><form id='ZaRLy'><ins id='ZaRLy'></ins><ul id='ZaRLy'></ul><sub id='ZaRLy'></sub></form><legend id='ZaRLy'></legend><bdo id='ZaRLy'><pre id='ZaRLy'><center id='ZaRLy'></center></pre></bdo></b><th id='ZaRLy'></th></span></q></dt></tr></i><div id='ZaRLy'><tfoot id='ZaRLy'></tfoot><dl id='ZaRLy'><fieldset id='ZaRLy'></fieldset></dl></div>
        <tfoot id='ZaRLy'></tfoot>
          <bdo id='ZaRLy'></bdo><ul id='ZaRLy'></ul>

        向Android中的AlertDialog添加垂直滚动条?

        时间:2023-08-31
        1. <small id='PmqCE'></small><noframes id='PmqCE'>

          <i id='PmqCE'><tr id='PmqCE'><dt id='PmqCE'><q id='PmqCE'><span id='PmqCE'><b id='PmqCE'><form id='PmqCE'><ins id='PmqCE'></ins><ul id='PmqCE'></ul><sub id='PmqCE'></sub></form><legend id='PmqCE'></legend><bdo id='PmqCE'><pre id='PmqCE'><center id='PmqCE'></center></pre></bdo></b><th id='PmqCE'></th></span></q></dt></tr></i><div id='PmqCE'><tfoot id='PmqCE'></tfoot><dl id='PmqCE'><fieldset id='PmqCE'></fieldset></dl></div>

            <tbody id='PmqCE'></tbody>

            • <bdo id='PmqCE'></bdo><ul id='PmqCE'></ul>

              <legend id='PmqCE'><style id='PmqCE'><dir id='PmqCE'><q id='PmqCE'></q></dir></style></legend>
              • <tfoot id='PmqCE'></tfoot>

                  本文介绍了向Android中的AlertDialog添加垂直滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想为 AlertDialog 添加一个垂直滚动条,因为我的文本太长而无法在 1 个屏幕上显示:

                  I would like to add a vertical scrollbar to an AlertDialog because my text is too long to display on 1 screen:

                  我试过用:

                  android:scrollbars="vertical" 
                  android:scrollbarAlwaysDrawVerticalTrack="true"
                  

                  但滚动条甚至不显示?

                  这是我正在使用的 xml 布局文件:

                  Here's the xml layout file I'm using:

                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:orientation="vertical"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:scrollbars="vertical"
                      android:scrollbarAlwaysDrawVerticalTrack="true"
                      android:id="@+id/instructions_view" >
                      <TextView
                          android:id="@+id/TextView01"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:text="A LONG TEXT 1"/>
                  
                      <TextView 
                          android:id="@+id/TextView02"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:text="A LONG TEXT 2"/>
                  
                  </LinearLayout>
                  

                  我用 :

                  public void onClick(View v) {
                    switch(v.getId()){
                  
                      case R.id.Button_Instructions: 
                       InstructionsDialog();
                      break;
                  
                      case R.id.Button_Exit: 
                       ExitDialog();
                      break;
                      }
                   }
                  
                  public void InstructionsDialog(){
                  
                    AlertDialog.Builder ad = new AlertDialog.Builder(this);
                    ad.setIcon(R.drawable.icon);
                    ad.setTitle("Instructions ...");
                    ad.setView(LayoutInflater.from(this).inflate(R.layout.instructions_dialog,null));
                  
                    ad.setPositiveButton("OK", 
                      new android.content.DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int arg1) {
                        // OK, go back to Main menu
                       }
                      }
                     );
                  
                     ad.setOnCancelListener(new DialogInterface.OnCancelListener(){
                      public void onCancel(DialogInterface dialog) {
                       // OK, go back to Main menu   
                      }}
                     );
                  
                    ad.show();
                   }
                  

                  我现在找到了答案 => 现在可以使用了:

                  I found the answer now=> IT WORKS NOW WITH THIS :

                  <?xml version="1.0" encoding="utf-8"?>
                  <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                      android:id="@+id/ScrollView01"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent">
                  
                      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                          android:orientation="vertical"
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:scrollbars="vertical"
                          android:scrollbarAlwaysDrawVerticalTrack="true"
                          android:id="@+id/instructions_view" >
                  
                          <TextView
                              android:id="@+id/TextView01"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:text="A LONG TEXT 1"/>
                  
                          <TextView
                              android:id="@+id/TextView02"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:text="A LONG TEXT 2"/>
                  
                      </LinearLayout>
                  </ScrollView>
                  

                  推荐答案

                  为了让视图可滚动,它必须嵌套在 ScrollView 容器内:

                  In order for a view to scrollable, it must be nested inside of a ScrollView container:

                  <ScrollView>
                      <LinearLayout android:orientation="vertical"
                              android:scrollbars="vertical"
                              android:scrollbarAlwaysDrawVerticalTrack="true">
                          <TextView />
                          <Button />
                      </LinearLayout>
                  </ScrollView>
                  

                  请注意,ScrollView 容器只能有一个子布局视图.例如,不能在没有 LinearLayout 的情况下将 TextViewButton 放置在 ScrollView 中.

                  Note that a ScrollView container can only have one child layout view. It is not possible, for example, to place a TextView and Button in a ScrollView without the LinearLayout.

                  这篇关于向Android中的AlertDialog添加垂直滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:是否可以在对话框内创建列表视图? 下一篇:点击按钮后 sendUserActionEvent() mView== null

                  相关文章

                  最新文章

                    • <bdo id='Ft23a'></bdo><ul id='Ft23a'></ul>
                    <i id='Ft23a'><tr id='Ft23a'><dt id='Ft23a'><q id='Ft23a'><span id='Ft23a'><b id='Ft23a'><form id='Ft23a'><ins id='Ft23a'></ins><ul id='Ft23a'></ul><sub id='Ft23a'></sub></form><legend id='Ft23a'></legend><bdo id='Ft23a'><pre id='Ft23a'><center id='Ft23a'></center></pre></bdo></b><th id='Ft23a'></th></span></q></dt></tr></i><div id='Ft23a'><tfoot id='Ft23a'></tfoot><dl id='Ft23a'><fieldset id='Ft23a'></fieldset></dl></div>
                  1. <small id='Ft23a'></small><noframes id='Ft23a'>

                      <tfoot id='Ft23a'></tfoot>

                      <legend id='Ft23a'><style id='Ft23a'><dir id='Ft23a'><q id='Ft23a'></q></dir></style></legend>