简体   繁体   中英

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.

I also don't want to hide the Android's button interface.

Without ScrollView 在此处输入图片说明

With ScrollView 在此处输入图片说明

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. Your phone will think it has to fill the whole screen. But that isn't neccesary because of your Android button (header) interface.

First of all weightsum that you are using in your LinearLayout is useless. Now, Why you are not seeing the button in your mobile but in preview is because in your preview, you have hidden the 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 . To do it efficiently, give your scrollview weight = 1 and your buttons as you have written in your above code.

`

<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 . Scrollview is given 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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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