在对话框中使用 Scrollview 时出现问题

2024-01-07

我正在对话框内膨胀布局,其中包含滚动视图,但布局不滚动。我已经从 stackoverflow 提到了很多问题,但它也不起作用。我的layout.xml如下:

<?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="match_parent"
        android:layout_margin="5dp"
        android:background="@color/White"
       >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/White"
        android:scrollbars="vertical"
            android:scrollbarAlwaysDrawVerticalTrack="true"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_margin="5dp"
            android:text="Update available"
            android:textColor="#000000" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:gravity="center"
            android:text="@string/upgrade_msg"
            android:textColor="#000000" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="300dp"
            android:layout_margin="3dp"
            android:layout_weight="0.02"
            android:src="@drawable/updateimg2" />

        <Button
            android:id="@+id/btn_upgrade"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_forget_pwd"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:background="@color/White"
            android:gravity="center"
            android:text="Upgrade Now"
            android:textColor="@color/Black" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:scaleType="fitXY"
            android:src="@drawable/line_y_h" />

        <Button
            android:id="@+id/btn_remind"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_forget_pwd"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:background="@color/White"
            android:gravity="center"
            android:text="Remind Me Later"
            android:textColor="@color/Blue" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:scaleType="fitXY"
            android:src="@drawable/line_y_h" />
    </LinearLayout>

</ScrollView>
  • 对话代码

      public void show_Alert_version_custom(String str, final String url,
                final String exitStatus)// use for
        {
            final Dialog dialog = new Dialog(Splash.this);
            dialog.setContentView(R.layout.version_update);
            dialog.setTitle(getString(R.string.alert_title));
            Button dialogButton2 = (Button) dialog.findViewById(R.id.btn_remind);
            dialogButton = (Button) dialog.findViewById(R.id.btn_upgrade);
            ImageView viewLine = (ImageView) dialog.findViewById(R.id.imageView2);
    
    
            // if button is clicked, close the custom dialog
            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {}
            });
    
            // if button is clicked, close the custom dialog
            dialogButton2.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {}
            });
    
            dialog.show();
        }
    

ScrollView 中的 android:fillViewport="true" 解决了我的问题。现在它甚至在对话框内滚动。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在对话框中使用 Scrollview 时出现问题 的相关文章

随机推荐