简体   繁体   English

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

[英]Android Interface Buttons hide the bottom of my application

I have no idea how to solve this. 我不知道该如何解决。 It displays well on the preview and when I run the last button is hidden by the interface. 它在预览中显示良好,当我运行时,界面隐藏了最后一个按钮。 It also happens when I add the ScrollView - it's not that. 当我添加ScrollView时也会发生这种情况,不是那样。

I also don't want to hide the Android's button interface. 我也不想隐藏Android的按钮界面。

Without ScrollView 没有ScrollView 在此处输入图片说明

With ScrollView 使用ScrollView 在此处输入图片说明

XML 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>

I think you should use fill_parent instead of match_parent for your container height. 我认为您应该使用fill_parent而不是match_parent作为容器的高度。 Your phone will think it has to fill the whole screen. 您的手机会认为它必须填满整个屏幕。 But that isn't neccesary because of your Android button (header) interface. 但这不是必需的,因为您的Android按钮(标题)界面。

First of all weightsum that you are using in your LinearLayout is useless. 首先,您在LinearLayout中使用的weightsum是无用的。 Now, Why you are not seeing the button in your mobile but in preview is because in your preview, you have hidden the actionbar . 现在,为什么在移动设备中却看不到按钮,而在预览中却是因为在预览中隐藏了操作actionbar Now, if you want to show the button in the layout then there are two ways:- 现在,如果要在布局中显示按钮,则有两种方法:

  1. You need to resize the views and make them smaller. 您需要调整视图的大小并使它们变小。 ( Unreliable an Not Recommended ) 不可靠,不推荐

  2. You need to out the views above your buttons in a ScrollView . 您需要在ScrollView按钮上方的视图。 To do it efficiently, give your scrollview weight = 1 and your buttons as you have written in your above code. 为了有效地做到这一点,请使您的scrollview weight = 1并像上面代码中编写的那样设置按钮。

` `

<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>

` `

What i'm doing over here is, Adding a Scrollview and two Buttons in a LinearLayout . 我在这里要做的是在LinearLayout添加一个Scrollviewtwo Buttons Scrollview is given android:layout_weight="1" . Scrollview被赋予android:layout_weight="1" Now what happens is, the buttons will take the space they need and rest of the space will be covered by ScrollView . 现在发生的是,按钮将占据它们所需的空间,而其余空间将被ScrollView覆盖。

Put the Linear layout inside scroll view. 将线性布局放入滚动视图中。 Because every mobile has different screen sizes, its best practice to put it inside a scroll view. 由于每个移动设备的屏幕尺寸都不同,因此最好将其放在滚动视图中。

<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>

Something like this should work. 这样的事情应该起作用。 Hope this helps!.. 希望这可以帮助!..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM