Android界面按钮隐藏了我的应用程序的底部

时间:2017-04-21 13:01:55

标签: android

我不知道如何解决这个问题。它在预览中显示良好,当我运行最后一个按钮时,界面将隐藏它。当我添加ScrollView时也会发生这种情况 - 它不是那样。

我也不想隐藏Android的按钮界面。

没有ScrollView enter image description here

使用ScrollView enter image description here

XML

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.tiagosilva.amob_android.ContactUsFragment"
android:background="@color/AMOB_gray">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp"
    android:weightSum="3">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="AMOB Headquarters"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="Rua Padre Domingos Joaquim Pereira,1249"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="4760-563 Louro"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white"
        android:background="@color/AMOB_gray"/>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="Vila Nova de Famalicão, Portugal"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="Phone: (+351) 252 330 900"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="Fax: (+351) 252 376 887"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView9"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="E-mail: comercial@amob.pt"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="GPS: 41º 26'.16''N / 8º32'31.89''W"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/gps_amob"
        android:id="@+id/gps_map"
        android:layout_weight="3"
        android:layout_marginTop="10dp"
        android:scaleType="fitXY"/>

    <Button
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/btn_emailUs"
        android:background="@drawable/round_buttons"
        android:layout_marginTop="10dp"
        android:text="Email us">
    </Button>

    <Button
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/btn_callUs"
        android:background="@drawable/round_buttons_green"
        android:layout_marginTop="10dp"
        android:text="Call Us">
    </Button>

</LinearLayout>
</FrameLayout>

3 个答案:

答案 0 :(得分:0)

我认为您应该使用fill_parent而不是match_parent作为容器高度。你的手机会认为它必须填满整个屏幕。但由于你的Android按钮(标题)界面,这不是必要的。

答案 1 :(得分:0)

首先,您在weightsum中使用的LinearLayout是无用的。 现在,为什么你没有看到手机中的按钮但是在预览中是因为在预览中你隐藏了actionbar。 现在,如果要在布局中显示按钮,则有两种方法: -

  1. 您需要调整视图大小并使其缩小。 (不可靠,不推荐

  2. 您需要在ScrollView中删除按钮上方的视图。 要有效地执行此操作,请按照上述代码中的说明提供滚动视图weight = 1和按钮。

  3. `

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="20dp">
    
                    <TextView
                        android:id="@+id/textView2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="serif"
                        android:text="AMOB Headquarters"
                        android:textAppearance="@style/TextAppearance.AppCompat"
                        android:textColor="@android:color/white"
                        android:textStyle="bold" />
    
                    <TextView
                        android:id="@+id/textView3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="serif"
                        android:text="Rua Padre Domingos Joaquim Pereira,1249"
                        android:textAppearance="@style/TextAppearance.AppCompat"
                        android:textColor="@android:color/white" />
    
                    <TextView
                        android:id="@+id/textView4"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/AMOB_gray"
                        android:fontFamily="serif"
                        android:text="4760-563 Louro"
                        android:textAppearance="@style/TextAppearance.AppCompat"
                        android:textColor="@android:color/white" />
    
                    <TextView
                        android:id="@+id/textView5"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="serif"
                        android:text="Vila Nova de Famalicão, Portugal"
                        android:textAppearance="@style/TextAppearance.AppCompat"
                        android:textColor="@android:color/white" />
    
                    <TextView
                        android:id="@+id/textView7"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="serif"
                        android:text="Phone: (+351) 252 330 900"
                        android:textAppearance="@style/TextAppearance.AppCompat"
                        android:textColor="@android:color/white" />
    
                    <TextView
                        android:id="@+id/textView8"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="serif"
                        android:text="Fax: (+351) 252 376 887"
                        android:textAppearance="@style/TextAppearance.AppCompat"
                        android:textColor="@android:color/white" />
    
                    <TextView
                        android:id="@+id/textView9"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="serif"
                        android:text="E-mail: comercial@amob.pt"
                        android:textAppearance="@style/TextAppearance.AppCompat"
                        android:textColor="@android:color/white" />
    
                    <TextView
                        android:id="@+id/textView6"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="serif"
                        android:text="GPS: 41º 26'.16''N / 8º32'31.89''W"
                        android:textAppearance="@style/TextAppearance.AppCompat"
                        android:textColor="@android:color/white" />
    
    
                    <ImageView
                        android:id="@+id/gps_map"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:scaleType="fitXY"
                        android:src="@drawable/gps_amob" />
                </LinearLayout>
            </ScrollView>
    
            <Button
                android:id="@+id/btn_emailUs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:background="@drawable/round_buttons"
                android:text="Email us"></Button>
    
            <Button
                android:id="@+id/btn_callUs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:background="@drawable/round_buttons_green"
                android:text="Call Us"></Button>
        </LinearLayout>
    

    `

    我在这里做的是,在Scrollview中添加two ButtonsLinearLayoutScrollviewandroid:layout_weight="1" ScrollView。 现在发生的是,按钮将占用他们需要的空间,其余的空间将由{{1}}覆盖。

答案 2 :(得分:0)

将“线性”布局放在滚动视图中。因为每个移动设备都有不同的屏幕尺寸,所以最好将它放在滚动视图中。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.tiagosilva.amob_android.ContactUsFragment"
android:background="@color/AMOB_gray">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp"
    android:weightSum="3">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="AMOB Headquarters"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="Rua Padre Domingos Joaquim Pereira,1249"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="4760-563 Louro"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white"
        android:background="@color/AMOB_gray"/>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="Vila Nova de Famalicão, Portugal"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="Phone: (+351) 252 330 900"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="Fax: (+351) 252 376 887"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView9"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="E-mail: comercial@amob.pt"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="serif"
        android:text="GPS: 41º 26'.16''N / 8º32'31.89''W"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textColor="@android:color/white" />


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/gps_amob"
        android:id="@+id/gps_map"
        android:layout_weight="3"
        android:layout_marginTop="10dp"
        android:scaleType="fitXY"/>

    <Button
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/btn_emailUs"
        android:background="@drawable/round_buttons"
        android:layout_marginTop="10dp"
        android:text="Email us">
    </Button>

    <Button
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/btn_callUs"
        android:background="@drawable/round_buttons_green"
        android:layout_marginTop="10dp"
        android:text="Call Us">
    </Button>

</LinearLayout>
</ScrollView>
</FrameLayout>

这样的事情应该有效。 希望这有帮助!..