【问题标题】:How to disable Overlay in RelativeLayout?如何在 RelativeLayout 中禁用覆盖?
【发布时间】:2014-04-21 05:49:21
【问题描述】:

如果我在两个字段之一中写入文本,最后的 textViews 会显示在按钮上...

那很糟糕。 我不想要它。 我正在寻找禁用它的可能性。 例如,如果显示键盘,可能会隐藏按钮
或使文本可滚动

不用担心网格,它有 9 行 TextViews

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/padding_small"
android:paddingLeft="@dimen/padding_small"
android:paddingRight="@dimen/padding_small"
tools:context=".ActivityMain_plain" >

<Button
    android:id="@+id/Button_berechnen"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:paddingBottom="@dimen/padding_small"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:text="@string/Button_berechnen" />

<EditText
    android:id="@+id/input_ipAdresse"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@+id/Button_berechnen"
    android:layout_toRightOf="@+id/tV_input_snm_txt"
    android:ems="10"
    android:gravity="right"
    android:inputType="phone"
    android:paddingRight="@dimen/padding_small"
    android:textSize="@dimen/fontsize_medium" >

    <requestFocus android:layout_width="match_parent" />

</EditText>


<EditText
    android:id="@+id/input_snm"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/input_ipAdresse"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/input_ipAdresse"
    android:ems="10"
    android:gravity="right"
    android:inputType="phone"
    android:paddingRight="@dimen/padding_small"
    android:textSize="@dimen/fontsize_medium" />

<TextView
    android:id="@+id/tV_input_snm_txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/input_snm"
    android:layout_alignParentLeft="true"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:paddingTop="@dimen/padding_small"
    android:text="@string/input_snm"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/tV_input_ipAdresse"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/input_ipAdresse"
    android:layout_alignParentLeft="true"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:paddingTop="@dimen/padding_small"
    android:text="@string/input_ipAdresse"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<GridLayout
    android:id="@+id/table_gridLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/input_snm"
    android:columnCount="5"
    android:fadingEdge="horizontal|vertical"
    android:paddingBottom="@dimen/padding_small"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:paddingTop="@dimen/padding_medium"
    android:scrollbars="horizontal|vertical" >

</GridLayout>

<TextView
    android:id="@+id/tV_Klasse"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/table_gridLayout"
    android:layout_marginTop="10dp"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:paddingTop="@dimen/padding_small"
    android:text="@string/txt_Klasse" />

<TextView
    android:id="@+id/tV_BitsNetz"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/tV_Klasse"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:text="@string/txt_BitsNetz" />

<TextView
    android:id="@+id/tV_BitsSubnetz"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/tV_BitsNetz_erg"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:text="@string/txt_BitsSubnetz" />

<TextView
    android:id="@+id/tV_BitsHost"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/tV_BitsSubnetz"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:text="@string/txt_BitsHost" />

<TextView
    android:id="@+id/tV_MagischeZahl"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/tV_BitsHost"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:text="@string/txt_MagischeZahl" />

<TextView
    android:id="@+id/tV_AnzahlHost"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/tV_AnzahlSubnetz"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:text="@string/txt_AnzHosts" />

<TextView
    android:id="@+id/tV_AnzahlSubnetz"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/tV_MagischeZahl"
    android:layout_below="@+id/tV_MagischeZahl"
    android:paddingLeft="@dimen/padding_small"
    android:paddingRight="@dimen/padding_small"
    android:paddingTop="@dimen/padding_small"
    android:text="@string/txt_AnzSubnetze" />

<TextView
    android:id="@+id/tV_Klasse_erg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/tV_Klasse"
    android:layout_alignBottom="@+id/tV_Klasse"
    android:layout_alignRight="@+id/input_snm"
    android:minWidth="100dp" />

<TextView
    android:id="@+id/tV_BitsNetz_erg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/tV_BitsNetz"
    android:layout_alignBottom="@+id/tV_BitsNetz"
    android:layout_alignLeft="@+id/tV_Klasse_erg"
    android:minWidth="100dp" />

<TextView
    android:id="@+id/tV_BitsSubnetz_erg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/tV_BitsSubnetz"
    android:layout_alignLeft="@+id/tV_Klasse_erg"
    android:minWidth="100dp" />

<TextView
    android:id="@+id/tV_BitsHost_erg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/tV_BitsHost"
    android:layout_alignBottom="@+id/tV_BitsHost"
    android:layout_alignLeft="@+id/tV_BitsNetz_erg"
    android:minWidth="100dp" />

<TextView
    android:id="@+id/tV_MagischeZahl_erg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/tV_MagischeZahl"
    android:layout_alignBottom="@+id/tV_MagischeZahl"
    android:layout_alignLeft="@+id/tV_BitsHost_erg"
    android:minWidth="100dp" />

<TextView
    android:id="@+id/tV_AnzahlSubnetz_erg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/tV_AnzahlSubnetz"
    android:layout_alignLeft="@+id/tV_BitsHost_erg"
    android:minWidth="100dp" />

<TextView
    android:id="@+id/tV_AnzahlHost_erg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/tV_AnzahlHost"
    android:layout_alignLeft="@+id/tV_MagischeZahl_erg"
    android:minWidth="100dp" />
</RelativeLayout>

我知道为什么,但是没有什么好的方法来解决它...... 我知道相对布局覆盖是可能的,但在这里我不想要它......

【问题讨论】:

  • 您的问题不清楚。你介意更新一下吗?
  • 并非如此。所以你想让你的视图,被你提供的 XML 布局膨胀,可滚动?
  • 我希望有可能禁用覆盖 - 可能使用完整的可滚动布局或隐藏按钮(在 java 中)或...

标签: java android xml layout android-relativelayout


【解决方案1】:

如果我理解正确,这可能会解决您的问题:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/RelativeLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/padding_small"
                android:paddingLeft="@dimen/padding_small"
                android:paddingRight="@dimen/padding_small"
                tools:context=".ActivityMain_plain">

    <Button
            android:id="@+id/Button_berechnen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:paddingBottom="@dimen/padding_small"
            android:paddingLeft="@dimen/padding_small"
            android:paddingRight="@dimen/padding_small"
            android:text="@string/Button_berechnen"/>

    <EditText
            android:id="@+id/input_ipAdresse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignRight="@+id/Button_berechnen"
            android:layout_toRightOf="@+id/tV_input_snm_txt"
            android:ems="10"
            android:gravity="right"
            android:inputType="phone"
            android:paddingRight="@dimen/padding_small"
            android:textSize="@dimen/fontsize_medium">

        <requestFocus android:layout_width="match_parent"/>

    </EditText>


    <EditText
            android:id="@+id/input_snm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/input_ipAdresse"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/input_ipAdresse"
            android:ems="10"
            android:gravity="right"
            android:inputType="phone"
            android:paddingRight="@dimen/padding_small"
            android:textSize="@dimen/fontsize_medium"/>

    <TextView
            android:id="@+id/tV_input_snm_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/input_snm"
            android:layout_alignParentLeft="true"
            android:paddingLeft="@dimen/padding_small"
            android:paddingRight="@dimen/padding_small"
            android:paddingTop="@dimen/padding_small"
            android:text="@string/input_snm"
            android:textAppearance="?android:attr/textAppearanceMedium"/>

    <TextView
            android:id="@+id/tV_input_ipAdresse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/input_ipAdresse"
            android:layout_alignParentLeft="true"
            android:paddingLeft="@dimen/padding_small"
            android:paddingRight="@dimen/padding_small"
            android:paddingTop="@dimen/padding_small"
            android:text="@string/input_ipAdresse"
            android:textAppearance="?android:attr/textAppearanceMedium"/>

    <ScrollView android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/Button_berechnen"
                android:layout_below="@+id/input_snm">

        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

            <GridLayout
                    android:id="@+id/table_gridLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:columnCount="5"
                    android:fadingEdge="horizontal|vertical"
                    android:paddingBottom="@dimen/padding_small"
                    android:paddingLeft="@dimen/padding_small"
                    android:paddingRight="@dimen/padding_small"
                    android:paddingTop="@dimen/padding_medium"
                    android:scrollbars="horizontal|vertical">

            </GridLayout>

            <TextView
                    android:id="@+id/tV_Klasse"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:paddingLeft="@dimen/padding_small"
                    android:paddingRight="@dimen/padding_small"
                    android:paddingTop="@dimen/padding_small"
                    android:text="@string/txt_Klasse"/>

            <TextView
                    android:id="@+id/tV_BitsNetz"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="@dimen/padding_small"
                    android:paddingRight="@dimen/padding_small"
                    android:text="@string/txt_BitsNetz"/>

            <TextView
                    android:id="@+id/tV_BitsSubnetz"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="@dimen/padding_small"
                    android:paddingRight="@dimen/padding_small"
                    android:text="@string/txt_BitsSubnetz"/>

            <TextView
                    android:id="@+id/tV_BitsHost"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="@dimen/padding_small"
                    android:paddingRight="@dimen/padding_small"
                    android:text="@string/txt_BitsHost"/>

            <TextView
                    android:id="@+id/tV_MagischeZahl"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="@dimen/padding_small"
                    android:paddingRight="@dimen/padding_small"
                    android:text="@string/txt_MagischeZahl"/>

            <TextView
                    android:id="@+id/tV_AnzahlHost"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="@dimen/padding_small"
                    android:paddingRight="@dimen/padding_small"
                    android:text="@string/txt_AnzHosts"/>

            <TextView
                    android:id="@+id/tV_AnzahlSubnetz"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="@dimen/padding_small"
                    android:paddingRight="@dimen/padding_small"
                    android:paddingTop="@dimen/padding_small"
                    android:text="@string/txt_AnzSubnetze"/>

            <TextView
                    android:id="@+id/tV_Klasse_erg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="100dp"/>

            <TextView
                    android:id="@+id/tV_BitsNetz_erg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="100dp"/>

            <TextView
                    android:id="@+id/tV_BitsSubnetz_erg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="100dp"/>

            <TextView
                    android:id="@+id/tV_BitsHost_erg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="100dp"/>

            <TextView
                    android:id="@+id/tV_MagischeZahl_erg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="100dp"/>

            <TextView
                    android:id="@+id/tV_AnzahlSubnetz_erg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="100dp"/>

            <TextView
                    android:id="@+id/tV_AnzahlHost_erg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="100dp"/>
        </LinearLayout>

    </ScrollView>

</RelativeLayout>

我还没有实际测试过代码,但这个概念应该是正确的。

另外,我强烈建议您重新审视您的 XML 布局,因为它可以改进。

【讨论】:

  • 重访是什么意思?我应该重温什么?
  • 也许我判断得太快了。如果它对你有用,那很好。我的解决方案能解决您的问题吗?
  • “无效的布局参数标记”
  • 请更具体。
  • 线性布局:警告:android:layout_alignParentLeft android:layout_below
猜你喜欢
  • 1970-01-01
  • 2014-05-17
  • 1970-01-01
  • 1970-01-01
  • 2016-02-07
  • 2018-08-03
  • 1970-01-01
  • 2017-08-17
相关资源
最近更新 更多