WebHU - Programozási kérdések és válaszok

Hogyan lehet a Számológép elrendezését a teljes képernyőre illeszteni?

Egy egyszerű Számológép alkalmazást készítek, és nem tudom beilleszteni az elrendezést az egész képernyőre. Van egy TextView, egy EditText és egy gombom, és van egy kis szóköz, ami alatta marad. Azt szeretném, hogy az elrendezésem a teljes képernyőre kiterjedjen, mint az Android Számológépe.

Az XML kódfájlom a következő:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.varun.calculator.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:lines="2"
            android:maxLines="2"
            android:textSize="35sp" />

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/textView"
            android:enabled="false"
            android:inputType="numberDecimal"
            android:lines="2"
            android:maxLines="2"
            android:textSize="20sp" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="vertical">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Button
                android:id="@+id/seven"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="7"
                android:textSize="25sp" />

            <Button
                android:id="@+id/eight"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:layout_toRightOf="@id/seven"
                android:text="8"
                android:textSize="25sp" />

            <Button
                android:id="@+id/nine"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:layout_toRightOf="@id/eight"
                android:text="9"
                android:textSize="25sp" />

            <Button
                android:id="@+id/four"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/seven"
                android:text="4"
                android:textSize="25sp" />

            <Button
                android:id="@+id/five"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/eight"
                android:layout_toRightOf="@id/four"
                android:text="5"
                android:textSize="25sp" />

            <Button
                android:id="@+id/six"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/nine"
                android:layout_toRightOf="@id/five"
                android:text="6"
                android:textSize="25sp" />

            <Button
                android:id="@+id/one"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/four"
                android:text="1"
                android:textSize="25sp" />

            <Button
                android:id="@+id/two"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/five"
                android:layout_toRightOf="@id/one"
                android:text="2"
                android:textSize="25sp" />

            <Button
                android:id="@+id/three"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/six"
                android:layout_toRightOf="@id/two"
                android:text="3"
                android:textSize="25sp" />

            <Button
                android:id="@+id/dot"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/one"
                android:text="."
                android:textSize="25sp" />

            <Button
                android:id="@+id/zero"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/two"
                android:layout_toRightOf="@id/dot"
                android:text="0"
                android:textSize="25sp" />

            <Button
                android:id="@+id/clear"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/three"
                android:layout_toRightOf="@id/zero"
                android:text="C"
                android:textSize="25sp" />


            <Button
                android:id="@+id/div"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:layout_toRightOf="@id/nine"
                android:text="/"
                android:textSize="25sp" />

            <Button
                android:id="@+id/mul"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/div"
                android:layout_toRightOf="@id/three"
                android:text="*"
                android:textSize="25sp" />

            <Button
                android:id="@+id/sub"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/mul"
                android:layout_toRightOf="@id/clear"
                android:text="-"
                android:textSize="25sp" />


            <Button
                android:id="@+id/equal"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/dot"
                android:text="="
                android:textSize="25sp" />


            <Button
                android:id="@+id/add"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/sub"
                android:layout_toRightOf="@id/three"
                android:text="+"
                android:textSize="25sp" />


        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

Kérjük, ellenőrizze az itt linkelt képet: 1


Válaszok:


1

Ez az xml lehet segítségedre, igényed szerint lefedi az egész oldalt.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:lines="2"
        android:maxLines="2"
        android:textSize="35sp" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView"
        android:enabled="false"
        android:inputType="numberDecimal"
        android:lines="2"
        android:maxLines="2"
        android:textSize="20sp" />


  </LinearLayout>

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:orientation="vertical">

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:id="@+id/seven"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="7"
            android:textSize="25sp" />

        <Button
            android:id="@+id/eight"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="8"
            android:textSize="25sp" />

        <Button
            android:id="@+id/nine"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="9"
            android:textSize="25sp" />

        <Button
            android:id="@+id/div"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="/"
            android:textSize="25sp" />

      </LinearLayout>

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <Button
            android:id="@+id/four"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="4"
            android:textSize="25sp" />

        <Button
            android:id="@+id/five"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="5"
            android:textSize="25sp" />

        <Button
            android:id="@+id/six"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="6"
            android:textSize="25sp" />

        <Button
            android:id="@+id/mul"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="*"
            android:textSize="25sp" />

        </LinearLayout>

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <Button
            android:id="@+id/one"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1"
            android:textSize="25sp" />

        <Button
            android:id="@+id/two"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2"
            android:textSize="25sp" />

        <Button
            android:id="@+id/three"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3"
            android:textSize="25sp" />

        <Button
            android:id="@+id/add"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="+"
            android:textSize="25sp" />

        </LinearLayout>

       <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <Button
            android:id="@+id/dot"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="."
            android:textSize="25sp" />

        <Button
            android:id="@+id/zero"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0"
            android:textSize="25sp" />

        <Button
            android:id="@+id/clear"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="C"
            android:textSize="25sp" />

        <Button
            android:id="@+id/sub"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="-"
            android:textSize="25sp" />
       </LinearLayout>

   </LinearLayout>

16.01.2017

2

Eltávolítás a szülő elrendezésből

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

SZERKESZTÉS

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.varun.calculator.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:lines="2"
        android:maxLines="2"
        android:textSize="35sp" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:enabled="false"
        android:inputType="numberDecimal"
        android:lines="2"
        android:maxLines="2"
        android:textSize="20sp" />


</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:orientation="vertical">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/seven"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:text="7"
            android:textSize="25sp" />

        <Button
            android:id="@+id/eight"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_toRightOf="@+id/seven"
            android:text="8"
            android:textSize="25sp" />

        <Button
            android:id="@+id/nine"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_toRightOf="@+id/eight"
            android:text="9"
            android:textSize="25sp" />

        <Button
            android:id="@+id/four"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/seven"
            android:text="4"
            android:textSize="25sp" />

        <Button
            android:id="@+id/five"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/eight"
            android:layout_toRightOf="@+id/four"
            android:text="5"
            android:textSize="25sp" />

        <Button
            android:id="@+id/six"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/nine"
            android:layout_toRightOf="@+id/five"
            android:text="6"
            android:textSize="25sp" />

        <Button
            android:id="@+id/one"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/four"
            android:text="1"
            android:textSize="25sp" />

        <Button
            android:id="@+id/two"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/five"
            android:layout_toRightOf="@+id/one"
            android:text="2"
            android:textSize="25sp" />

        <Button
            android:id="@+id/three"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/six"
            android:layout_toRightOf="@+id/two"
            android:text="3"
            android:textSize="25sp" />

        <Button
            android:id="@+id/dot"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/one"
            android:text="."
            android:textSize="25sp" />

        <Button
            android:id="@+id/zero"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/two"
            android:layout_toRightOf="@+id/dot"
            android:text="0"
            android:textSize="25sp" />

        <Button
            android:id="@+id/clear"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/three"
            android:layout_toRightOf="@+id/zero"
            android:text="C"
            android:textSize="25sp" />


        <Button
            android:id="@+id/div"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_toRightOf="@+id/nine"
            android:text="/"
            android:textSize="25sp" />

        <Button
            android:id="@+id/mul"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/div"
            android:layout_toRightOf="@+id/three"
            android:text="*"
            android:textSize="25sp" />

        <Button
            android:id="@+id/sub"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/mul"
            android:layout_toRightOf="@+id/clear"
            android:text="-"
            android:textSize="25sp" />


        <Button
            android:id="@+id/equal"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/dot"
            android:text="="
            android:textSize="25sp" />


        <Button
            android:id="@+id/add"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/sub"
            android:layout_toRightOf="@+id/three"
            android:text="+"
            android:textSize="25sp" />


    </RelativeLayout>
</LinearLayout>
</LinearLayout>
16.01.2017
  • Kipróbáltam, nem működött. Ha ellenőrzi a képet, szeretném, ha a = gombom az aljához igazodik. Ez az a tér, amitől meg akarok szabadulni. 16.01.2017
  • Ez az android:layout_below=@id/mul hibás. Ennek a következőnek kell lennie: android:layout_below=@+id/mul, valamint az a hely, ahol a @id/xyz értéket használja. Ezt a következőre kell cserélni: @+id/xyz 16.01.2017
  • @VarunJoshi Megkaptad?? 16.01.2017
  • Nem, úgy tűnik, nem tudom kiterjeszteni az elrendezésemet, hogy betöltse a képernyőt :( 16.01.2017
  • Változtattál, ahogy mondtam? Megosztod a képernyőképet? 16.01.2017
  • igen, bár nem értettem az id mezőben szükséges változtatásokat 16.01.2017

  • 3

    A relatív elrendezésben a android:layout_height="wrap_content" megőrzése helyett próbálja meg az értéket android:layout_height="match_parent" értéken tartani, és azt javaslom, hogy mindegyikhez tartson azonos súlyértékeket... Próbálkozzon ezzel. És lehet, hogy ha ezeknek a lépéseknek a végrehajtása után még marad üres hely, akkor távolítsa el a android:padddingBottom

    16.01.2017
  • Olyan egyszerű! Haha nem hiszem el, hogy 4 órát töltöttem azzal, hogy kísérleteztem az elrendezési súlyokkal. Kösz! 16.01.2017
  • Rendben van, én is gyakran elakadok ezeknél a dolgoknál. 16.01.2017
  • Új anyagok

    A rádiógomb ellenőrzött eseményének használata a jQueryben
    Ebben a cikkben látni fogjuk, hogyan kell dolgozni a jquery választógombbal ellenőrzött eseményeivel. A választógombok HTML gombok, amelyek segítenek kiválasztani egyetlen értéket egy csoportból...

    Körkörös függőségek megoldása terraformban adatforrásokkal – lépésről lépésre
    Mi az a körkörös függőségek Dolgozzunk egy egyszerű eseten, amikor az SQS-sor és az S3-vödör közötti körkörös függőség problémája van egy egymástól függő címkeérték miatt. provider..

    Miért érdemes elkezdeni a kódolást 2023-ban?
    01100011 01101111 01100100 01100101 — beep boop beep boop Világunk folyamatosan fejlődik a technológia körül, és naponta fejlesztenek új technológiákat a valós problémák megoldására. Amint..

    🎙 Random Noise #2  – Örökbefogadás és hit
    az analitika íratlan világának gondozása Szeretné, hogy ezek a frissítések a postaládájába kerüljenek? Iratkozzon fel itt . "Ha önvezető autókat gyártanak, akkor mi miért ne..

    A legrosszabb politika és prediktív modellek májátültetésre jelöltek számára az Egyesült Államokban
    A máj (vagy óangolul lifer) az emberi test legnehezebb belső szervére utal, amely csendesen működik a nap 24 órájában. Mit csinál a máj? 500 feladatot hajt végre a szervezet egészségének..

    5 webhely, amely 2022-ben fejleszti front-end fejlesztői készségeit
    Frontendmentor.io A tényleges projektek létrehozásával a Frontendmentor.io segítséget nyújt a front-end kódolási képességeinek fejlesztésében. A kódolást azután kezdheti meg, hogy..

    Mikor kell használni a Type-t az interfészhez képest a TypeScriptben?
    A TypeScript a JavaScript gépelt szuperkészlete, amely statikus gépelést ad a nyelvhez. Ez megkönnyíti a robusztus és karbantartható kód írását azáltal, hogy a hibákat a fordítási időben..