Androidrelativelayout自定义对话框问题

标签 android android-relativelayout customdialog

我的相对布局需要一些帮助。当我启动自定义对话框时,看不到我的“关闭”按钮。只有当我将 ScollView 高度设置为“200dp”左右时才能看到它。我不想手动设置高度。有办法实现吗?也许使用 android:weightSum?请告诉我它是如何完成的。谢谢

OnMenuItemClickListener mAboutButtonClickListener = new OnMenuItemClickListener() {

         @Override
            public boolean onMenuItemClick(MenuItem item) {  

                final Dialog dialog = new Dialog(MainPageActivity.this);
                dialog.setContentView(R.layout.about_us);
                dialog.setTitle("About Us");
                dialog.setCancelable(true);

                TextView text = (TextView) dialog.findViewById(R.id.TextView01);

                try {
                    Resources res = getResources();
                    InputStream in_s = res.openRawResource(R.raw.disclaimer);

                    byte[] b = new byte[in_s.available()];
                    in_s.read(b);
                    text.setText(new String(b));

                } catch (Exception e) {
                    // e.printStackTrace();
                    text.setText("Error: can't show help.");
                }


                //set up button
                Button button = (Button) dialog.findViewById(R.id.Button01);
                button.setOnClickListener(new OnClickListener() {
                @Override
                    public void onClick(View v) {

                    dialog.dismiss();
                    }
                });


                dialog.show();
                return false;
            }
        };

我的xml

 <?xml version="1.0" encoding="utf-8"?>


        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
              >

        <ScrollView android:id="@+id/ScrollView01" 
                    android:layout_width="wrap_content" 
                    android:layout_height="wrap_content" 
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:scrollbars="vertical" 
                    android:scrollbarAlwaysDrawVerticalTrack="true">

        <TextView   android:id="@+id/TextView01"
                    android:layout_width="wrap_content" 
                android:layout_height="wrap_content"/>

        </ScrollView>

        <Button android:id="@+id/Button01" 
                android:layout_below="@+id/ScrollView01"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true" 
                android:text="Close"
                        android:layout_alignParentBottom="true"/>
    </RelativeLayout>

最佳答案

你可以使用这样的东西。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/root"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >

<ScrollView
  android:layout_width="match_parent"
  android:layout_height="0dip"
  android:layout_weight="1" >

 <TextView   android:id="@+id/TextView01"
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content"/>

 </ScrollView>

 <Button android:id="@+id/Button01" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:text="Close" />

 </LinearLayout>

关于Androidrelativelayout自定义对话框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12138454/

相关文章:

android - 登录页面中的水平线

android - 将按钮对齐到屏幕底部

android - 使用 setMultiChoiceItems 的自定义对话框

android - 点击按钮后 sendUserActionEvent() mView== null

android - 自定义对话框在 android 顶部提供空白

android - 如何为 Google Places API get AutocompletePrediction() 方法提供合理的默认范围?

android - jsonArrayRequest 失败

xamarin.forms - Xamarin 表单 : How to place one layout on top of another layout

java - 如果不存在则插入,否则根据用户的选择更新 android

android - 从 Firebase 存储加载图像但使用 Glide 时出错