Adattare app ad ogni schermo

  • Creatore Discussione Creatore Discussione kalimett
  • Data di inizio Data di inizio

kalimett

Utente Attivo
29 Apr 2011
39
0
0
Ciao a tutti,
sono un giovane sviluppatore che si sta dedicando ad una calcolatrice in material design. Purtroppo c'è un problema: non riesco ad adattare i tasti ad ogni schermo, infatti sul mio Xperia s (4.3 pollici) i tasti risultano troppo piccoli mentre con un nexus 5 i tasti sono della dimensione perfetta. Come faccio a fare in modo che si adattino ad ogni schermo? Posto qui sotto il codice xml
Codice:
<RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background = "#ffffff"
    android:textSize="35dp">


<TextView
    android:id="@+id/twone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="0dp"
    android:layout_marginTop="0dp"
    android:background="#5677fc"
    android:text="0"
    android:textSize="35dp" />


    <Button
        android:id="@+id/buttonsplit"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonfour"
        android:layout_alignParentRight="true"
        android:onClick="sendMessageSplit"
        android:text="@string/button_split"
        android:background="#ffffff" />


    <Button
        android:id="@+id/buttonnine"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonfour"
        android:layout_toRightOf="@+id/buttoneight"
        android:onClick="sendMessageNine"
        android:text="@string/button_nine"
        android:background="#ffffff" />


    <Button
        android:id="@+id/buttoneight"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonfour"
        android:layout_toRightOf="@+id/buttonsseven"
        android:onClick="sendMessageEight"
        android:text="@string/button_eight"
        android:background="#ffffff" />


    <Button
        android:id="@+id/buttonzero"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonnine"
        android:onClick="sendMessageZero"
        android:text="@string/button_zero" 
        android:background="#ffffff"/>


    <Button
        android:id="@+id/buttonfour"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonone"
        android:background="#ffffff"
        android:onClick="sendMessageFour"
        android:text="@string/button_four" />


    <Button
        android:id="@+id/buttonless"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/buttonone"
        android:onClick="sendMessageLess"
        android:text="@string/button_less"
        android:background="#ffffff" />


    <Button
        android:id="@+id/buttonone"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/twone"
        android:layout_alignParentRight="false"
        android:onClick="sendMessageOne"
        android:text="@string/button_one"
        android:background="#ffffff" />
    
      
      <Button
          android:id="@+id/buttonsix"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_below="@+id/buttonone"
          android:layout_toRightOf="@+id/buttonfive"
          android:onClick="sendMessageSix"
          android:text="@string/button_six"
          android:background="#ffffff" />


      <Button
          android:id="@+id/buttonsseven"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_below="@+id/buttonfive"
          android:layout_alignParentRight="false"
          android:onClick="sendMessageSeven"
          android:text="@string/button_seven"
          android:background="#ffffff" />


      <Button
          android:id="@+id/buttonthree"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_toRightOf="@+id/buttontwo"
          android:layout_below="@+id/twone"
          android:onClick="sendMessageThree"
          android:text="@string/button_three" 
          android:background="#ffffff"/>


      <Button
          android:id="@+id/buttonfive"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_below="@+id/buttontwo"
          android:layout_toRightOf="@+id/buttonfour"
          android:onClick="sendMessageFive"
          android:text="@string/button_five"
          android:background="#ffffff" />


      <Button
          android:id="@+id/buttontwo"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_toRightOf="@+id/buttonone"
          android:layout_below="@+id/twone"
          android:onClick="sendMessageTwo"
          android:text="@string/button_two"
          android:background="#ffffff" />


      <Button
          android:id="@+id/buttonplus"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_below="@+id/twone"
          android:layout_alignParentRight="true"
          android:onClick="sendMessagePlus"
          android:text="@string/button_plus"
          android:background="#ffffff"
           />
      

      <Button
          android:id="@+id/buttonfor"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_alignBaseline="@+id/buttonzero"
          android:layout_alignBottom="@+id/buttonzero"
          android:layout_toLeftOf="@+id/buttonnine"
          android:onClick="sendMessageFor"
          android:text="@string/button_for"
          android:background="#ffffff"
           />
      
       <com.faizmalkani.floatingactionbutton.FloatingActionButton
        android:id="@+id/fabbutton"
        android:layout_width="72dp"
        android:layout_height="72dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:onClick="fabClicked"
        app:drawable="@drawable/ic_av_equal2"
        app:color="#5677fc" />
 
Ciao a tutti,
sono un giovane sviluppatore che si sta dedicando ad una calcolatrice in material design. Purtroppo c'è un problema: non riesco ad adattare i tasti ad ogni schermo, infatti sul mio Xperia s (4.3 pollici) i tasti risultano troppo piccoli mentre con un nexus 5 i tasti sono della dimensione perfetta. Come faccio a fare in modo che si adattino ad ogni schermo? Posto qui sotto il codice xml
Codice:
<RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background = "#ffffff"
    android:textSize="35dp">


<TextView
    android:id="@+id/twone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="0dp"
    android:layout_marginTop="0dp"
    android:background="#5677fc"
    android:text="0"
    android:textSize="35dp" />


    <Button
        android:id="@+id/buttonsplit"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonfour"
        android:layout_alignParentRight="true"
        android:onClick="sendMessageSplit"
        android:text="@string/button_split"
        android:background="#ffffff" />


    <Button
        android:id="@+id/buttonnine"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonfour"
        android:layout_toRightOf="@+id/buttoneight"
        android:onClick="sendMessageNine"
        android:text="@string/button_nine"
        android:background="#ffffff" />


    <Button
        android:id="@+id/buttoneight"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonfour"
        android:layout_toRightOf="@+id/buttonsseven"
        android:onClick="sendMessageEight"
        android:text="@string/button_eight"
        android:background="#ffffff" />


    <Button
        android:id="@+id/buttonzero"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonnine"
        android:onClick="sendMessageZero"
        android:text="@string/button_zero" 
        android:background="#ffffff"/>


    <Button
        android:id="@+id/buttonfour"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/buttonone"
        android:background="#ffffff"
        android:onClick="sendMessageFour"
        android:text="@string/button_four" />


    <Button
        android:id="@+id/buttonless"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/buttonone"
        android:onClick="sendMessageLess"
        android:text="@string/button_less"
        android:background="#ffffff" />


    <Button
        android:id="@+id/buttonone"
        android:layout_width="80dp"
        android:layout_height="100dp"
        android:layout_below="@+id/twone"
        android:layout_alignParentRight="false"
        android:onClick="sendMessageOne"
        android:text="@string/button_one"
        android:background="#ffffff" />
    
      
      <Button
          android:id="@+id/buttonsix"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_below="@+id/buttonone"
          android:layout_toRightOf="@+id/buttonfive"
          android:onClick="sendMessageSix"
          android:text="@string/button_six"
          android:background="#ffffff" />


      <Button
          android:id="@+id/buttonsseven"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_below="@+id/buttonfive"
          android:layout_alignParentRight="false"
          android:onClick="sendMessageSeven"
          android:text="@string/button_seven"
          android:background="#ffffff" />


      <Button
          android:id="@+id/buttonthree"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_toRightOf="@+id/buttontwo"
          android:layout_below="@+id/twone"
          android:onClick="sendMessageThree"
          android:text="@string/button_three" 
          android:background="#ffffff"/>


      <Button
          android:id="@+id/buttonfive"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_below="@+id/buttontwo"
          android:layout_toRightOf="@+id/buttonfour"
          android:onClick="sendMessageFive"
          android:text="@string/button_five"
          android:background="#ffffff" />


      <Button
          android:id="@+id/buttontwo"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_toRightOf="@+id/buttonone"
          android:layout_below="@+id/twone"
          android:onClick="sendMessageTwo"
          android:text="@string/button_two"
          android:background="#ffffff" />


      <Button
          android:id="@+id/buttonplus"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_below="@+id/twone"
          android:layout_alignParentRight="true"
          android:onClick="sendMessagePlus"
          android:text="@string/button_plus"
          android:background="#ffffff"
           />
      

      <Button
          android:id="@+id/buttonfor"
          android:layout_width="80dp"
          android:layout_height="100dp"
          android:layout_alignBaseline="@+id/buttonzero"
          android:layout_alignBottom="@+id/buttonzero"
          android:layout_toLeftOf="@+id/buttonnine"
          android:onClick="sendMessageFor"
          android:text="@string/button_for"
          android:background="#ffffff"
           />
      
       <com.faizmalkani.floatingactionbutton.FloatingActionButton
        android:id="@+id/fabbutton"
        android:layout_width="72dp"
        android:layout_height="72dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:onClick="fabClicked"
        app:drawable="@drawable/ic_av_equal2"
        app:color="#5677fc" />

Ciao,
dovresti creare dei file risorsa per ogni schermo, in modo che l'app vada a caricare i parametri corretti a seconda del dispositivo in uso. In tal modo ogni dispositivo caricherà l'app con le dimensioni corrette.

Ti consiglio di dare una lettura alla guida developer Android: http://developer.android.com/training/multiscreen/index.html

Un saluto.
 

Discussioni simili