【问题标题】:ScrollView hides top elements of the layoutScrollView 隐藏布局的顶部元素
【发布时间】:2023-04-09 08:45:01
【问题描述】:

我有非常简单的对话框布局并添加了滚动视图,因为对话框可能很长并且不适合屏幕 当我最初运行对话框(它适合屏幕)时,一切都很好,然后我将设备方向更改为横向,对话框不再适合屏幕,出现滚动,但几个顶部元素(直到 @+id/addr_label)变得不可见虽然标题和第一个可见元素之间出现了一些空白空间。最令人困惑的是 - 当我将设备改回纵向视图时 - 这些元素仍然不可见。

更新:刚刚检查了手机最初处于横向模式时的情况 - 在这种情况下,所有元素都正确显示。当我将其改回纵向时-元素消失了。似乎是一个“改变方向”的错误

可能是什么问题?

布局和截图如下(Android是2.3.5)

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root22" android:orientation="vertical"
    android:layout_width="wrap_content" android:layout_height="fill_parent"
    android:padding="0dp">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root" android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:padding="10dp">

    <TextView android:id="@+id/details_ssid"
        android:layout_width="wrap_content" 
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="" 
        android:layout_marginLeft="5dip"/>

    <TextView android:id="@+id/details_bssid"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="" 
        android:layout_weight="1"
        android:layout_marginLeft="5dip"/>

    <TextView android:id="@+id/latitude"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="" 
        android:layout_weight="1"
        android:layout_marginLeft="5dip"/>

    <TextView android:id="@+id/longitude"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="" 
        android:layout_weight="1"
        android:layout_marginLeft="5dip"/>

    <TextView android:id="@+id/addr_label"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="@string/address_label" 
        android:layout_weight="1"
        android:layout_marginLeft="5dip"/>

    <EditText android:id="@+id/address"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="" 
        android:layout_weight="1"
        android:layout_marginLeft="5dip"/>

    <TextView android:id="@+id/descr_label"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="@string/description_label" 
        android:layout_weight="1"
        android:layout_marginLeft="5dip"/>

    <EditText android:id="@+id/description"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:text="" 
        android:layout_weight="1"
        android:layout_marginLeft="5dip"/>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout_root" android:orientation="horizontal"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:padding="10dp">

    <Button
    android:id="@+id/yes"
        android:layout_width="fill_parent" 
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true" 
        android:layout_alignParentBottom="true"
        android:layout_marginTop="10dip" 
        android:layout_marginRight="10dip"
        android:text= "@string/Yes"
        android:visibility="visible"
    />


    <Button
    android:id="@+id/no"
        android:layout_width="fill_parent" 
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" 
        android:layout_alignParentBottom="true"
        android:layout_marginTop="10dip" 
        android:layout_marginRight="10dip"
        android:text= "@string/No"
        android:visibility="visible"
    />  
    </LinearLayout>

    </LinearLayout> 

</ScrollView>

代码很无聊: Activity 中的 onCreateDialog 设置布局和 onPrepareDialog 为所有这些字段设置值

onCreateDialog

    case CONFIRM_SHARE_AP:
    {
        final Dialog dialog = new Dialog(this){
            public void onBackPressed()
            {
                dismissDialog(CONFIRM_SHARE_AP);
            }
        };

        dialog.setContentView(R.layout.ap_add_confirmation);

        dialog.setTitle(R.string.confirm_share);

        Button cancel = (Button) dialog.findViewById(R.id.no);
        cancel.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                dismissDialog(CONFIRM_SHARE_AP);

            }
        });
        return dialog;          
    }

onPrepareDialog 没有什么特别的

http://img525.imageshack.us/img525/4642/devicev1.png

http://img13.imageshack.us/img13/985/devicev2.png

【问题讨论】:

  • IImage 太小,打不开。例如,尝试使用更知名的服务器,例如 imageshack。并且不要调整它的大小。
  • 乍一看,我不认为这是布局的问题。我认为设置这些视图内容的代码存在问题。您应该发布相关代码。
  • 你在滚动视图中尝试过 android:fillViewport="true" 吗?
  • dmon,添加了代码。我不认为这是一个原因,因为第一次显示正常。 Maneesh - 尝试过 - 没有运气

标签: android layout


【解决方案1】:

找到了问题的根源。 这是因为在方向更改期间活动会重新启动(默认情况下),因此会重新创建对话框。

【讨论】:

    猜你喜欢
    • 2014-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 2011-12-16
    相关资源
    最近更新 更多