9

Non riesco a trovare la causa principale della distorsione di seguito.
UI funziona correttamente ma quando ruoto lo schermo in orizzontale, l'interfaccia utente viene distorta durante lo scorrimento.
Questa distorsione continua quando lo schermo viene nuovamente ruotato in verticale.Interfaccia utente distorta Android

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="8dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <include layout="@layout/i_details" /> 

     <include layout="@layout/v_details" /> 

     <include layout="@layout/d_details" /> 
    </LinearLayout> 


</ScrollView> 

UPDATE
i_details

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="4dp" 
    android:orientation="vertical"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:background="@color/colorPrimary"> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left|bottom" 
      android:layout_margin="4dp" 
      android:text="Large Text" 
      android:textSize="25sp" /> 

    </FrameLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:elevation="4dp" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="4dp" 
      android:layout_margin="8dp" 
      android:text="Message" 
      android:textSize="14sp" /> 

     <TextView 
      android:id="@+id/message" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="top|start" 
      android:layout_margin="8dp" 
      android:text="RANDOM TEXT" 
      android:textSize="18sp" /> 

    </LinearLayout> 

</LinearLayout> 


v_details

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_margin="4dp"> 

    <ImageView 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:adjustViewBounds="true" 
     android:scaleType="centerCrop" 
     android:layout_alignParentTop="true" 
     android:background="@color/colorPrimary" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/navigateFab" 
     android:layout_width="61dp" 
     android:layout_height="61dp" 
     android:layout_gravity="bottom|end" 
     android:layout_marginRight="12dp" 
     android:layout_marginBottom="-24dp" 
     android:background="@color/colorAccent" 
     android:contentDescription="navigation" 
     android:elevation="8dp" 
     android:src="@drawable/ic_navigate_24dp" 
     app:pressedTranslationZ="2dp" 
     android:layout_above="@+id/linearLayout" 
     android:layout_alignParentEnd="true" /> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:elevation="4dp" 
     android:layout_below="@id/map" 
     android:orientation="vertical" 
     android:id="@+id/linearLayout"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:layout_marginTop="4dp" 
      android:text="Random Text" 
      android:textSize="14sp" /> 

     <TextView 
      android:id="@+id/name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:gravity="top|start" 
      android:text="Random Text" 
      android:textSize="18sp" /> 

     <TextView 
      android:id="@+id/address" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:drawablePadding="4dp" 
      android:drawableStart="@drawable/ic_place_24dp" 
      android:gravity="top|start" 
      android:text="Random Text" 
      android:textSize="18sp" /> 

     <TextView 
      android:id="@+id/phone" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:autoLink="phone" 
      android:clickable="true" 
      android:drawablePadding="4dp" 
      android:drawableStart="@drawable/ic_call_24dp" 
      android:gravity="top|start" 
      android:text="Random Text" 
      android:textSize="16sp" /> 

     <TextView 
      android:id="@+id/website" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:autoLink="web" 
      android:clickable="true" 
      android:drawablePadding="4dp" 
      android:drawableStart="@drawable/ic_language_24dp" 
      android:gravity="top|start" 
      android:text="Random Text" 
      android:textSize="16sp" /> 

    </LinearLayout> 

</RelativeLayout> 


d_details

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="4dp" 
    android:elevation="4dp" 
    android:orientation="vertical"> 


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:layout_marginTop="4dp" 
     android:text="Random Text" 
     android:textSize="14sp" /> 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:gravity="top|start" 
     android:text="Random Text" 
     android:textSize="18sp" /> 

    <TextView 
     android:id="@+id/address" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:drawablePadding="4dp" 
     android:drawableStart="@drawable/ic_place_24dp" 
     android:gravity="top|start" 
     android:text="Random Text" 
     android:textSize="18sp" /> 

    <TextView 
     android:id="@+id/phone" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:autoLink="phone" 
     android:clickable="true" 
     android:drawablePadding="4dp" 
     android:drawableStart="@drawable/ic_call_24dp" 
     android:gravity="top|start" 
     android:text="Random Text" 
     android:textSize="16sp" /> 

    <TextView 
     android:id="@+id/email" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:autoLink="email" 
     android:clickable="true" 
     android:drawablePadding="4dp" 
     android:drawableStart="@drawable/ic_mail_24dp" 
     android:gravity="top|start" 
     android:text="Random Text" 
     android:textSize="16sp" /> 


</LinearLayout> 


UPDATE 3
codice attività aggiunto e ha dichiarato la logica frammento


i_activity

public class MYActivity extends AppCompatActivity { 
    private static final String LOG_TAG = MYActivity.class.getSimpleName(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_invitation); 

     MYFragment myFragment = new MYFragment(); 

     // In case this activity was started with special instructions from an 
     // Intent, pass the Intent's extras to the fragment as arguments 
     myFragment.setArguments(getIntent().getExtras()); 

     // Add the fragment to the 'my_container' FrameLayout 
     getSupportFragmentManager().beginTransaction().add(R.id.my_container, myFragment).commit(); 
    } 

    @Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 
     recreate(); 
    } 
} 


nel frammento, vado a prendere l'ID passato da un'attività, popolare la mia interfaccia utente statica,
iniziato CURSORE CARICATORE

@Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     Log.d(LOG_TAG, "Activity Created"); 
     getLoaderManager().initLoader(CURSOR_LOADER, getArguments(), this); 
     super.onActivityCreated(savedInstanceState); 
    } 

e
onLoadFinished (Loader loader, cursore Cursore)
prendere e popolano direttamente le mie opinioni dinamici dell'interfaccia utente.
Non si utilizza alcun adattatore in quanto tutte le viste sono semplici viste di testo.

I layout inclusi sono layout semplici con LinearLayout come contenitore padre e FrameLayout o LinearLayout come child e altre viste.

Sto utilizzando Picasso lib per caricare la mappa statica.
UPDATE 2 Picasso non è il problema, dopo aver rimosso Picasso, il problema rimane.
dispositivo: Nexus 5 sistema operativo Android: 6.0.1

enter image description here

+0

aggiungere xml di layout incluso anche –

+0

è inoltre necessario progettare un layout per la modalità orizzontale. allora andrà bene. –

+0

puoi anche aggiungere questa riga in modo più maneggevole nel tag attività android: configChanges = "keyboard | keyboardHidden | orientation | screenLayout" aggiungendo questo il tuo layout non verrà creato di nuovo quando ruoterai lo schermo –

risposta

4

Il problema è che il frammento viene creato due volte sull'orientamento Modifica Controllare saveInstancestate prima di creare un nuovo oggetto frammento.

private MYFragment myfragment;//define fragment globally 

    if(savedInstanceState == null) { 
     myfragment= new MYFragment();//set tag for fragment 
     getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, headlines, FRAGMENT_TAG_STRING).commit(); // Use tags, it's simpler to deal with 

    } else { 
     myfragment= getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_STRING); 
    } 
+0

Grazie mille: D –

1

Prova a cambiare la tua XML come illustrato di seguito nel campione.

L'idea è: è necessario mantenere l'intera cosa in un layout relativo. Una volta utilizzato il layout relativo, ti dà la possibilità di posizionare gli oggetti uno sopra l'altro.

<?xml version="1.0" encoding="utf-8"?> 
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="8dp"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
     <LinearLayout 
      android:id="@+id/one" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <include layout="@layout/activity_line_graph" 
       android:id="@+id/two" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/one"/> 

      <include layout="@layout/activity_my_stocks" 
       android:id="@+id/three" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/two"/> 

      <include layout="@layout/widget_collection" 
       android:id="@+id/four" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/three"/> 
     </LinearLayout> 
     </RelativeLayout> 

    </ScrollView> 

includono ciascuno dovrebbe,

  1. un ID da cui.
  2. hanno anche larghezza e altezza altrimenti, la posizione sopra o sotto viene ignorata. Spero che questo aiuti ed ehi, ti auguro una splendida festa di compleanno :) auguri in anticipo!
+0

verificherà. grazie per il desiderio ... ancora 5-6 mesi;): D –

+0

non ha aiutato :( –

+0

Vedo, potresti modificare i layout inclusi per mostrare i dettagli completi? A partire da ora è tagliato e non lo fa mostra l'intero codice –

1

Provare a chiamare il metodo invalidate() del decoro quando l'orientamento è cambiato.

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { 
     this.getWindow().getDecorView().invalidate(); 
    } 
} 

Spero che questo possa essere d'aiuto.

+0

non risolto :( –

+0

L'idea è di forzare il ridisegno del layout ... questo è solo un passo per indagare ... ok prova a chiamare recreate(); invece di this.getWindow(). getDecorView(). invalidate(); ... –

+0

ancora lo stesso problema :( –

Problemi correlati