2017-09-11 4 views
0

Derzeit entwickle ich eine Anwendung für ein Android-Tablet. Ich suche nach einer Methode oder einem Ansatz, um den Bildschirm in zwei Teile zu teilen und eine Unteransicht sichtbar zu machen. Ich weiß nicht, wo ich diesen Effekt gefunden habe (iOS- oder Android-App).Android teilen Aktivität in zwei Teile

Zur Illustration Ich habe zwei Bilder angehängt:

enter image description here

Nach einem Klick auf Ansicht X ein Subview genau unten angezeigt werden soll (der Rest des Bildschirms nach unten bewegt wird):

enter image description here

Kennt jemand diesen Effekt? Grüße!

Antwort

1

in Android Studio können Sie ein Fragment in Ihre Aktivität aufblasen.

Hier ist das Beispiel:

in Main2Activity.java

public class Main2Activity extends AppCompatActivity { 

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

     final FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLayout); 
     Button btn = (Button) findViewById(R.id.button3); 
     btn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       PlusOneFragment myf = new PlusOneFragment(); 
       frameLayout.setVisibility(View.VISIBLE); 
       FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
       transaction.add(R.id.frameLayout, myf); 
       transaction.commit(); 

      } 
     }); 
    } 
} 

in activity_main2.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.testing.testinglibraryapps.Main2Activity"> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginStart="8dp" /> 

    <Button 
     android:id="@+id/button4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginEnd="8dp" /> 

    <FrameLayout 
     android:id="@+id/frameLayout" 
     android:layout_width="0dp" 
     android:layout_height="200dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginTop="0dp" 
     android:visibility="gone" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/button3"> 

    </FrameLayout> 

    <Button 
     android:id="@+id/button5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginTop="0dp" 
     app:layout_constraintTop_toBottomOf="@+id/frameLayout" /> 

    <Button 
     android:id="@+id/button6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginTop="0dp" 
     app:layout_constraintTop_toBottomOf="@+id/frameLayout" /> 
</android.support.constraint.ConstraintLayout> 

einen Blick darauf werfen, habe ich einen Trick von framelayout Sichtbarkeit um die Ansicht zu setzen unter sie gehen runter.

und für PlusOneFragment in meinem Beispiel, kann u es mit Ihrem eigenen Fragment

0

Sie können dies viele Art und Weise erreichen ändern ist. Das einfachste was ich mir vorstellen kann, ist eine View zu haben, die man einfach direkt ein-/ausblenden kann.

Layout:

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


    <LinearLayout <!-- this is the top layout --> 
     android:id:@+id/myTopLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation=horizontal> 

     .... YOUR LAYOUT VIEWS .... 

    </LinearLayout> 

    <LinearLayout <!-- this is layout you will show/hide --> 
     android:id:@+id/myShowHideLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation=horizontal 
     android:visibility="gone"> 

     .... YOUR LAYOUT VIEWS .... 

    </LinearLayout> 

    <LinearLayout <!-- this is the bottom layout --> 
     android:id:@+id/myBottomLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation=horizontal> 

     .... YOUR LAYOUT VIEWS .... 

    </LinearLayout> 

</LinearLayout> 

Nun müssen nur Ihre Aktivität anzeigen oder ausblenden Sie Mitte Layout, in dem Sie sich wie so wollen:

LinearLayout myShowHideLayout; 

... onCreate(...){ 

    myShowHideLayout = (LinearLayout)findViewById(R.id. myShowHideLayout); 
    myShowHideLayout.setVisibility(View.VISIBLE); 
}